home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bmp3.zip / VIEWWND.C < prev    next >
C/C++ Source or Header  |  1995-11-06  |  13KB  |  377 lines

  1. #pragma    title("Icon/Pointer Viewer  --  Version 1  --  (ViewWnd.C)")
  2. #pragma    subtitle("   Module Purpose - Interface Definitions")
  3.  
  4. #define    INCL_GPI           /* Include OS/2 PM GPI Interface    */
  5. #define    INCL_WIN           /* Include OS/2 PM Windows Interface    */
  6.  
  7. #include <malloc.h>
  8. #include <os2.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12.  
  13. #include "appdefs.h"
  14. #include "viewico.h"
  15.  
  16. /* This    module contains    routine    used to    handle the main    application    */
  17. /* client window.                            */
  18.  
  19. /* Filename:   ViewWnd.C                        */
  20.  
  21. /*  Version:   1                            */
  22. /*  Created:   1995-10-18                        */
  23. /*  Revised:   1995-10-18                        */
  24.  
  25. /* Routines:   static VOID SizeBitmapStack(HWND    hWnd);            */
  26. /*           MRESULT EXPENTRY    ViewWndProc(HWND hWnd, ULONG msg,    */
  27. /*                        MPARAM mp1,    MPARAM mp2);    */
  28.  
  29.  
  30. /************************************************************************/
  31. /************************************************************************/
  32. /************************************************************************/
  33. /* DISCLAIMER OF WARRANTIES:                        */
  34. /* -------------------------                        */
  35. /* The following [enclosed] code is sample code    created    by IBM        */
  36. /* Corporation and Prominare Inc.  This    sample code is not part    of any    */
  37. /* standard IBM    product    and is provided    to you solely for the purpose    */
  38. /* of assisting    you in the development of your applications.  The code    */
  39. /* is provided "AS IS",    without    warranty of any    kind.  Neither IBM nor    */
  40. /* Prominare shall be liable for any damages arising out of your    */
  41. /* use of the sample code, even    if they    have been advised of the    */
  42. /* possibility of such damages.                        */
  43. /************************************************************************/
  44. /************************************************************************/
  45. /************************************************************************/
  46. /*               D I S C L A I M E R                */
  47. /* This    code is    provided on an as is basis with    no implied support.    */
  48. /* It should be    considered freeware that cannot    be rebundled as        */
  49. /* part    of a larger "*ware" offering without our consent.        */
  50. /************************************************************************/
  51. /************************************************************************/
  52. /************************************************************************/
  53.  
  54. /* Copyright ╕ International Business Machines Corp., 1995.        */
  55. /* Copyright ╕ 1995  Prominare Inc.  All Rights    Reserved.        */
  56.  
  57. /* --------------------------------------------------------------------    */
  58.  
  59. HBITMAP    hbmROP = 0;           /* Bitmap Handle            */
  60. LONG    lScale = 100L;           /* Scale Factor            */
  61. RECTL    rclDest;           /* Destination Rectangle        */
  62. RECTL    rclImage;           /* Image Rectangle            */
  63. POINTL    aptlArea[8];           /* Shadow Points            */
  64. RECTL    rclROP;               /* ROP Image    Rectangle        */
  65. LONG    cxROP;               /* ROP Image    Width            */
  66. LONG    cyROP;               /* ROP Image    Height            */
  67. LONG    cxImage;           /* Bitmap Image Width        */
  68. LONG    cyImage;           /* Bitmap Image Height        */
  69. LONG    lHorzRange;           /* Horizontal Scroll    Bar Range    */
  70. LONG    lVertRange;           /* Vertical Scroll Bar Range        */
  71. LONG    lHorzPos;           /* Horizontal Scroll    Bar Position    */
  72. LONG    lVertPos;           /* Vertical Scroll Bar Position    */
  73. LONG    cxWindow;           /* Window Width            */
  74. LONG    cyWindow;           /* Window Height            */
  75.  
  76. LONG    iImage;               /* Bitmap Image Index        */
  77.  
  78. BOOL    fBitmapArray = TRUE;       /* Bitmap Array Display Flag        */
  79.  
  80. static VOID SizeBitmapStack(HWND hWnd);
  81.  
  82. #pragma    subtitle("   Module Purpose - Bitmap Stack Sizing Function")
  83. #pragma    page( )
  84.  
  85. /* --- SizeBitmapStack --------------------------------    [ Private ] ---    */
  86. /*                                    */
  87. /*     This function is    used to    calculate the size and position    of    */
  88. /*     the bitmaps from    the bitmap array for the window.        */
  89. /*                                    */
  90. /*     Upon Entry:                            */
  91. /*                                    */
  92. /*     HWND hWnd; = Window Handle                    */
  93. /*                                    */
  94. /*     Upon Exit:                            */
  95. /*                                    */
  96. /*     Nothing                                */
  97. /*                                    */
  98. /* --------------------------------------------------------------------    */
  99.  
  100. static VOID SizeBitmapStack(HWND hWnd)
  101.  
  102. {
  103. BITMAPINFOHEADER bmp;           /* Bitmap Information Header        */
  104. RECTL         rcl;           /* Window Rectangle            */
  105. LONG         cx;           /* Bitmap Width            */
  106. LONG         cy;           /* Bitmap Height            */
  107. LONG         xImage;       /* Image Starting Point        */
  108. register INT i;               /* Loop Counter            */
  109.  
  110.  
  111. WinQueryWindowRect(hWnd, &rcl);
  112.     
  113. for ( i    = 0, cx    = 10 * (cBitmaps - 1), cy = 0L;    i < cBitmaps; i++ )
  114.    {
  115.    GpiQueryBitmapParameters(abm[i].hbm,    &bmp);
  116.  
  117.    cx += bmp.cx;
  118.    if (    bmp.cy > cy )
  119.        cy = bmp.cy;
  120.    }
  121.  
  122. rclImage.xRight    = (rclImage.xLeft   = ((rcl.xRight - rcl.xLeft)    / 2L) -    (cx / 2L)) + cx;
  123. rclImage.yTop    = (rclImage.yBottom = ((rcl.yTop - rcl.yBottom)    / 2L) -    (cy / 2L)) + cy;
  124.  
  125. xImage = rclImage.xLeft;
  126.  
  127. rclImage.xLeft     -= 3L;
  128. rclImage.yBottom -= 3L;
  129. rclImage.xRight     += 3L;
  130. rclImage.yTop     += 3L;
  131.  
  132. for ( i    = 0; i < cBitmaps; i++ )
  133.    {
  134.    GpiQueryBitmapParameters(abm[i].hbm,    &bmp);
  135.  
  136.    abm[i].rclDest.xRight = (abm[i].rclDest.xLeft   = xImage) + bmp.cx;
  137.    abm[i].rclDest.yTop     = (abm[i].rclDest.yBottom = ((rcl.yTop    - rcl.yBottom) / 2L) - (bmp.cy / 2L)) +    bmp.cy;
  138.  
  139.                /* Form the final boundary points        */
  140.  
  141.    abm[i].aptlArea[0].x    = abm[i].rclDest.xLeft    - 2L;
  142.    abm[i].aptlArea[0].y    = abm[i].rclDest.yTop    + 2L;
  143.    abm[i].aptlArea[1].x    = abm[i].rclDest.xRight    + 2L;
  144.    abm[i].aptlArea[1].y    = abm[i].rclDest.yTop    + 2L;
  145.  
  146.    abm[i].aptlArea[2].x    = abm[i].rclDest.xRight     + 2L;
  147.    abm[i].aptlArea[2].y    = abm[i].rclDest.yBottom - 2L;
  148.    abm[i].aptlArea[3].x    = abm[i].rclDest.xLeft     - 2L;
  149.    abm[i].aptlArea[3].y    = abm[i].rclDest.yBottom - 2L;
  150.  
  151.    abm[i].aptlArea[4].x    = abm[i].rclDest.xLeft    - 1L;
  152.    abm[i].aptlArea[4].y    = abm[i].rclDest.yTop    + 1L;
  153.    abm[i].aptlArea[5].x    = abm[i].rclDest.xRight    + 1L;
  154.    abm[i].aptlArea[5].y    = abm[i].rclDest.yTop    + 1L;
  155.  
  156.    abm[i].aptlArea[6].x    = abm[i].rclDest.xRight     + 1L;
  157.    abm[i].aptlArea[6].y    = abm[i].rclDest.yBottom - 1L;
  158.    abm[i].aptlArea[7].x    = abm[i].rclDest.xLeft     - 1L;
  159.    abm[i].aptlArea[7].y    = abm[i].rclDest.yBottom - 1L;
  160.  
  161.    xImage += (bmp.cx + 10L);
  162.    }
  163. }
  164. #pragma    subtitle("   Client Window - Client Window Procedure")
  165. #pragma    page( )
  166.  
  167. /* --- ROPsTestWndProc --------------------------------- [ Public ] ---    */
  168. /*                                    */
  169. /*     This function is    used to    process    the messages sent to the    */
  170. /*     applications client window.                    */
  171. /*                                    */
  172. /*     Upon Entry:                            */
  173. /*                                    */
  174. /*     HWND   hWnd; = Window Handle                    */
  175. /*     ULONG  msg;  = PM Message                    */
  176. /*     MPARAM mp1;  = Message Parameter    1                */
  177. /*     MPARAM mp2;  = Message Parameter    2                */
  178. /*                                    */
  179. /*     Upon Exit:                            */
  180. /*                                    */
  181. /*     ROPsTestWndProc = Message Handling Result            */
  182. /*                                    */
  183. /* --------------------------------------------------------------------    */
  184.  
  185. MRESULT    EXPENTRY ViewWndProc(HWND hWnd,    ULONG msg, MPARAM mp1, MPARAM mp2)
  186.  
  187. {
  188. CHAR            szTitle[300];  /* Title    Bar Text        */
  189. HPS            hPS;       /* Presentation Space Handle        */
  190. PCHAR            pch;       /* String Character Pointer        */
  191. RECTL            rcl;       /* Window Rectangle            */
  192. POINTL            ptl;       /* Display Point            */
  193. register INT i;               /* Index                */
  194.  
  195. switch ( msg )
  196.    {
  197. /************************************************************************/
  198. /* Window being    created, perform window    initialization            */
  199. /************************************************************************/
  200.  
  201.    case    WM_CREATE :
  202.  
  203.        hptrWait     = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT,    FALSE);
  204.        hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW,    FALSE);
  205.  
  206.        cxScreen    = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  207.  
  208.        hmenuView = WinWindowFromID(WinQueryWindow(hWnd,    QW_PARENT), FID_MENU);
  209.  
  210.                /************************************************/
  211.                /* PDSGetTemplate is used to allow controls in  */
  212.                /* windows.  Do not remove this function    if you */
  213.                /* intend to include controls within the    window.*/
  214.                /************************************************/
  215.  
  216.        PDSGetTemplate(hWnd, WIN_VIEWER);
  217.        break;
  218.  
  219. /************************************************************************/
  220. /* Window being    sized                            */
  221. /************************************************************************/
  222.  
  223.    case    WM_SIZE    :
  224.        SizeBitmapStack(hWnd);
  225.        break;
  226.  
  227. /************************************************************************/
  228. /* Perform menu    initialization                        */
  229. /************************************************************************/
  230.  
  231.    case    WM_INITMENU :
  232.        switch (    SHORT1FROMMP(mp1) )
  233.        {
  234.        case    IDM_FILE :
  235.            break;
  236.  
  237.        }
  238.        break;
  239.  
  240. /************************************************************************/
  241. /* Process key press from keyboard                    */
  242. /************************************************************************/
  243.  
  244.    case    WM_CHAR    :
  245.                /************************************************/
  246.                /* PDSKeyProc is    used to    allow controls in      */
  247.                /* windows.  Do not remove this function    if you */
  248.                /* intend to include controls within the    window.*/
  249.                /************************************************/
  250.  
  251.        return(PDSKeyProc(hWnd, msg, mp1, mp2));
  252.  
  253. /************************************************************************/
  254. /* Process control selections                        */
  255. /************************************************************************/
  256.  
  257.    case    WM_COMMAND :
  258.        switch (    SHORT1FROMMP(mp1) )
  259.        {
  260.        case    IDM_OPEN :
  261.            if ( WinDlgBox(HWND_DESKTOP, hwndViewFrame, (PFNWP)OpenDlgProc,
  262.                   (HMODULE)NULL, DLG_OPEN, NULL) )
  263.            {
  264.            WinSetPointer(HWND_DESKTOP, hptrWait);
  265.            if (    (pch = strrchr(szBitmapFile, '.')) != NULL )
  266.                if ( !memicmp(pch, ".ico", 5) )
  267.                GetIconPointer(szBitmapFile,    TRUE);
  268.                else
  269.                GetIconPointer(szBitmapFile,    FALSE);
  270.            else
  271.                GetIconPointer(szBitmapFile, FALSE);
  272.            SizeBitmapStack(hWnd);
  273.            WinInvalidateRect(hWnd, NULL, FALSE);
  274.            strcat(memcpy(szTitle, "Icon/Pointer Viewer - ", 23), szBitmapFile);
  275.            if (    fWindowsBitmap )
  276.                strcat(szTitle, " [Windows 3.x format]");
  277.            else
  278.                if ( f20Bitmap )
  279.                strcat(szTitle, " [OS/2 2.x format]");
  280.                else
  281.                strcat(szTitle, " [OS/2 1.x format]");
  282.            WinSetWindowText(hwndViewFrame, szTitle);
  283.            WinSetPointer(HWND_DESKTOP, hptrArrow);
  284.            }
  285.            break;
  286.        }
  287.        break;
  288.    case    WM_BUTTON2DOWN :
  289.  
  290. /************************************************************************/
  291. /* Button 2 being depressed                        */
  292. /************************************************************************/
  293.  
  294.        ptl.x = (LONG)(SHORT)SHORT1FROMMP(mp1);
  295.        ptl.y = (LONG)(SHORT)SHORT2FROMMP(mp1);
  296.        for ( i = 0; i <    cBitmaps; i++ )
  297.        if (    WinPtInRect(hAB, &abm[i].rclDest, &ptl)    )
  298.            {
  299.            iBitmap = i;
  300.            WinDlgBox(HWND_DESKTOP, hwndViewFrame, (PFNWP)ViewDlgProc,
  301.              (HMODULE)NULL,    DLG_VIEW, NULL);
  302.            break;
  303.            }
  304.        break;
  305.  
  306. /************************************************************************/
  307. /* Erase window    background                        */
  308. /************************************************************************/
  309.  
  310.    case    WM_ERASEBACKGROUND :
  311.        WinQueryWindowRect(hWnd,    &rcl);
  312.        WinFillRect((HPS)LONGFROMMP(mp1), &rcl, CLR_PALEGRAY);
  313.        break;
  314.  
  315. /************************************************************************/
  316. /* Paint client    window                            */
  317. /************************************************************************/
  318.  
  319.    case    WM_PAINT :
  320.        GpiCreateLogColorTable(hPS = WinBeginPaint(hWnd,    (HPS)NULL, &rcl), 0UL, LCOLF_RGB, 0L, 0L, (PLONG)NULL);
  321.  
  322.                /* Display the bitmap array images side-by-side    */
  323.  
  324.        WinFillRect(hPS,    &rcl, RGBCLR_PALEGRAY);
  325.        for ( i = 0; i <    cBitmaps; i++ )
  326.        {
  327.                /* Draw the bitmap from the array        */
  328.  
  329.        WinDrawBitmap(hPS, abm[i].hbm, (PRECTL)NULL,    (PPOINTL)(PVOID)&abm[i].rclDest,
  330.              RGB_WHITE, RGB_BLACK, DBM_NORMAL);
  331.  
  332.                /* Draw the 3-D frame around the    image        */
  333.  
  334.        GpiSetColor(hPS, RGBCLR_SHADOW);
  335.        GpiMove(hPS,    &abm[i].aptlArea[7]);
  336.        GpiPolyLine(hPS, 2L,    &abm[i].aptlArea[4]);
  337.  
  338.        GpiSetColor(hPS, RGB_WHITE);
  339.        GpiPolyLine(hPS, 2L,    &abm[i].aptlArea[6]);
  340.  
  341.        GpiSetColor(hPS, RGB_BLACK);
  342.        GpiMove(hPS,    &abm[i].aptlArea[3]);
  343.        GpiPolyLine(hPS, 2L,    &abm[i].aptlArea[0]);
  344.  
  345.        GpiSetColor(hPS, RGBCLR_PALEGRAY);
  346.        GpiPolyLine(hPS, 2L,    &abm[i].aptlArea[2]);
  347.        }
  348.        WinEndPaint(hPS);
  349.        break;
  350.  
  351. /************************************************************************/
  352. /* Window being    destroyed, perform clean-up operations            */
  353. /************************************************************************/
  354.  
  355.    case    WM_DESTROY :
  356.  
  357.        for ( i = 0; i <    cBitmaps; i++ )
  358.        {
  359.        GpiDeleteBitmap(abm[i].hbmMask);
  360.  
  361.        if (    abm[i].hbmImage    )
  362.            GpiDeleteBitmap(abm[i].hbmImage);
  363.  
  364.        GpiDeleteBitmap(abm[i].hbm);
  365.        }
  366.  
  367.        if ( pb )
  368.        free(pb);
  369.        break;
  370.  
  371.                /* Default message processing            */
  372.    default :
  373.        return(WinDefWindowProc(hWnd, msg, mp1, mp2));
  374.    }
  375. return(0L);
  376. }
  377.