home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bmp2.zip / ROPSWND.C < prev    next >
C/C++ Source or Header  |  1995-08-13  |  28KB  |  833 lines

  1. #pragma    title("ROP Viewer  --  Version 1  --  (ROPsWnd.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 <stdlib.h>
  11.  
  12. #include "appdefs.h"
  13. #include "rops.h"
  14.  
  15. /* This    module contains    routine    used to    handle the main    application    */
  16. /* client window.                            */
  17.  
  18. /* Filename:   ROPsWnd.C                        */
  19.  
  20. /*  Version:   1                            */
  21. /*  Created:   1995-08-06                        */
  22. /*  Revised:   1995-08-14                        */
  23.  
  24. /* Routines:   static VOID CreateROPBitmap(HWND    hWnd);            */
  25. /*           static VOID SizeBitmap(HWND hWnd);            */
  26. /*           static VOID SizeBitmapStack(HWND    hWnd);            */
  27. /*           MRESULT EXPENTRY    ROPsTestWndProc(HWND hWnd, ULONG msg,    */
  28. /*                        MPARAM mp1, MPARAM mp2);*/
  29.  
  30.  
  31. /************************************************************************/
  32. /************************************************************************/
  33. /************************************************************************/
  34. /* DISCLAIMER OF WARRANTIES:                        */
  35. /* -------------------------                        */
  36. /* The following [enclosed] code is sample code    created    by IBM        */
  37. /* Corporation and Prominare Inc.  This    sample code is not part    of any    */
  38. /* standard IBM    product    and is provided    to you solely for the purpose    */
  39. /* of assisting    you in the development of your applications.  The code    */
  40. /* is provided "AS IS",    without    warranty of any    kind.  Neither IBM nor    */
  41. /* Prominare shall be liable for any damages arising out of your    */
  42. /* use of the sample code, even    if they    have been advised of the    */
  43. /* possibility of such damages.                        */
  44. /************************************************************************/
  45. /************************************************************************/
  46. /************************************************************************/
  47. /*               D I S C L A I M E R                */
  48. /* This    code is    provided on an as is basis with    no implied support.    */
  49. /* It should be    considered freeware that cannot    be rebundled as        */
  50. /* part    of a larger "*ware" offering without our consent.        */
  51. /************************************************************************/
  52. /************************************************************************/
  53. /************************************************************************/
  54.  
  55. /* Copyright ╕ International Business Machines Corp., 1995.        */
  56. /* Copyright ╕ 1995  Prominare Inc.  All Rights    Reserved.        */
  57.  
  58. /* --------------------------------------------------------------------    */
  59.  
  60. HBITMAP    hbmROP = 0;           /* Bitmap Handle            */
  61. LONG    lScale = 100L;           /* Scale Factor            */
  62. RECTL    rclDest;           /* Destination Rectangle        */
  63. RECTL    rclImage;           /* Image Rectangle            */
  64. POINTL    aptlArea[8];           /* Shadow Points            */
  65. RECTL    rclROP;               /* ROP Image    Rectangle        */
  66. LONG    cxROP;               /* ROP Image    Width            */
  67. LONG    cyROP;               /* ROP Image    Height            */
  68. LONG    cxImage;           /* Bitmap Image Width        */
  69. LONG    cyImage;           /* Bitmap Image Height        */
  70. LONG    lHorzRange;           /* Horizontal Scroll    Bar Range    */
  71. LONG    lVertRange;           /* Vertical Scroll Bar Range        */
  72. LONG    lHorzPos;           /* Horizontal Scroll    Bar Position    */
  73. LONG    lVertPos;           /* Vertical Scroll Bar Position    */
  74. LONG    cxWindow;           /* Window Width            */
  75. LONG    cyWindow;           /* Window Height            */
  76.  
  77. LONG    iImage;               /* Bitmap Image Index        */
  78.  
  79. BOOL    fBitmapArray = TRUE;       /* Bitmap Array Display Flag        */
  80.  
  81. HWND    hwndHScroll;
  82. HWND    hwndVScroll;
  83.  
  84. static VOID CreateROPBitmap(HWND hWnd);
  85. static VOID SizeBitmap(HWND hWnd);
  86. static VOID SizeBitmapStack(HWND hWnd);
  87.  
  88. #pragma    subtitle("   Module Purpose - Bitmap Sizing Function")
  89. #pragma    page( )
  90.  
  91. /* --- CreateROPBitmap --------------------------------    [ Private ] ---    */
  92. /*                                    */
  93. /*     This function is    used to    create the array of ROP    images.        */
  94. /*                                    */
  95. /*     Upon Entry:                            */
  96. /*                                    */
  97. /*     Nothing                                */
  98. /*                                    */
  99. /*     Upon Exit:                            */
  100. /*                                    */
  101. /*     Nothing                                */
  102. /*                                    */
  103. /* --------------------------------------------------------------------    */
  104.  
  105. static VOID CreateROPBitmap(HWND hWnd)
  106.  
  107. {
  108. BITMAPINFOHEADER  bmp;           /* Bitmap Information Header        */
  109. BITMAPINFOHEADER2 bminfo2;       /* Bitmap Information Header        */
  110. HBITMAP          hbmConstruct;       /* Bitmap Handle            */
  111. HDC          hDC;           /* Device Context Handle        */
  112. HPS          hpsBitmap;       /* Bitmap Presentation Space    Handle    */
  113. LONG          cFormats;       /* Formats Count            */
  114. LONG          lROP = 0L;       /* ROP Value                */
  115. PLONG          plFormats;       /* Formats Array            */
  116. POINTL          aptl[4];       /* Conversion Point            */
  117. RECTL          rcl;           /* Window Rectangle            */
  118. SIZEL          sizl;           /* Sizing Structure            */
  119. register INT i,    n;           /* Loop Counters            */
  120.  
  121. if ( hbmROP )
  122.    GpiDeleteBitmap(hbmROP);
  123.  
  124. GpiQueryBitmapParameters(hbmView, &bmp);
  125.  
  126.                /* Get bitmap device context handle for the main    */
  127.                /* Client Window                    */
  128.  
  129. if ( !(hDC = DevOpenDC(hAB, OD_MEMORY, "*", 0L,    0L, 0L)) )
  130.    return((HBITMAP)NULL);
  131.                /* Create bitmap    presentation space specifying    */
  132.                /* entire map Client Window for size required    */
  133.  
  134. WinQueryWindowRect(hWnd, &rcl);
  135. lHorzRange = (cxROP = sizl.cx =    bmp.cx * 16L + 150L) - (cxWindow = rcl.xRight -    rcl.xLeft);
  136. lVertRange = (cyROP = sizl.cy =    bmp.cy * 16L + 150L) - (cyWindow = rcl.yTop - rcl.yBottom);
  137.  
  138. WinSendMsg(hwndVScroll,    SBM_SETSCROLLBAR, MPFROMSHORT(lVertPos),
  139.        MPFROM2SHORT(0, lVertRange));
  140. WinSendMsg(hwndVScroll,    SBM_SETTHUMBSIZE, MPFROM2SHORT(cyWindow, cyROP), 0L);
  141.  
  142. WinSendMsg(hwndHScroll,    SBM_SETSCROLLBAR, MPFROMSHORT(lHorzPos),
  143.        MPFROM2SHORT(0, lHorzRange));
  144. WinSendMsg(hwndHScroll,    SBM_SETTHUMBSIZE, MPFROM2SHORT(cxWindow, cxROP), 0L);
  145.  
  146. rclROP.xLeft   = 0L;
  147. rclROP.yBottom = cyROP - cyWindow;
  148. rclROP.xRight  = cxWindow;
  149. rclROP.yTop    = cyROP;
  150.  
  151. cxImage    = bmp.cx + 10L;
  152. cyImage    = bmp.cy + 10L;
  153.  
  154. if ( !(hpsBitmap = GpiCreatePS(hAB, hDC, &sizl,    PU_PELS    | GPIT_NORMAL |    GPIA_ASSOC)) )
  155.    {
  156.                /* Error    occurred during    creation of        */
  157.                /* presentation space, close device context    */
  158.    DevCloseDC(hDC);
  159.    return((HBITMAP)NULL);
  160.    }
  161.                /* Get the number of bitmap formats that    the    */
  162.                /* display driver supports            */
  163.  
  164. DevQueryCaps(hDC, CAPS_BITMAP_FORMATS, 1L, &cFormats);
  165.  
  166.                /* Get the bitmap display formats.  The first    */
  167.                /* set within the array will be the one that    */
  168.                /* most closely matches the display device.    */
  169.  
  170. GpiQueryDeviceBitmapFormats(hpsBitmap, cFormats    * 2L,
  171.                 plFormats =    (PLONG)malloc(2UL * cFormats * sizeof(LONG)));
  172.  
  173.                /* Create actual    bitmap storage for colour wheel    */
  174.                /* having the default plane and bit count    */
  175.  
  176. memset(&bminfo2, 0, sizeof(BITMAPINFOHEADER2));
  177. bminfo2.cbFix      = sizeof(BITMAPINFOHEADER2);
  178. bminfo2.cx      = (ULONG)sizl.cx;
  179. bminfo2.cy      = (ULONG)sizl.cy;
  180. bminfo2.cPlanes      = (USHORT)plFormats[0];
  181. bminfo2.cBitCount = (USHORT)plFormats[1];
  182.  
  183. free(plFormats);
  184.  
  185. if ( !(hbmConstruct = GpiCreateBitmap(hpsBitmap, &bminfo2, 0L, 0L, 0L))    )
  186.    {
  187.                /* Error    occurred during    creation of bitmap    */
  188.                /* storage, destroy presentation    space created    */
  189.                /* and close device context opened        */
  190.  
  191.    GpiDestroyPS(hpsBitmap);
  192.    DevCloseDC(hDC);
  193.    return((HBITMAP)NULL);
  194.    }
  195.                /* Set bitmap as    current    bitmap to use        */
  196.  
  197. GpiSetBitmap(hpsBitmap,    hbmConstruct);
  198.  
  199.                /* Draw the page                    */
  200. GpiErase(hpsBitmap);
  201.  
  202. aptl[0].x = 0L;
  203. aptl[0].y = sizl.cy - bmp.cy;
  204. aptl[1].x = bmp.cx;
  205. aptl[1].y = sizl.cy;
  206.  
  207. aptl[2].x = aptl[2].y =    0L;
  208. aptl[3].x = bmp.cx;
  209. aptl[3].y = bmp.cy;
  210.  
  211. GpiSetPattern(hpsBitmap, lPattern);
  212.  
  213. for ( i    = 0; i < 16; i++ )
  214.    {
  215.    for ( n = 0;    n < 16;    n++ )
  216.        {
  217.        rcl.xLeft   = aptl[0].x;
  218.        rcl.xRight  = aptl[1].x + 1L;
  219.        rcl.yBottom = aptl[0].y;
  220.        rcl.yTop       = aptl[1].y + 1L;
  221.        WinFillRect(hpsBitmap, &rcl, lFillColour);
  222.        GpiWCBitBlt(hpsBitmap, hbmView, 4L, aptl, lROP++, BBO_IGNORE);
  223.        aptl[0].x += (bmp.cx + 10L);
  224.        aptl[1].x += (bmp.cx + 10L);
  225.        }
  226.    aptl[0].y -=    (bmp.cy    + 10L);
  227.    aptl[1].y -=    (bmp.cy    + 10L);
  228.    aptl[0].x = 0L;
  229.    aptl[1].x = bmp.cx;
  230.    }
  231.                /* Set the bitmap to allow completion of    bitmap    */
  232.                /* in memory                    */
  233.  
  234. GpiSetBitmap(hpsBitmap,    (HDC)NULL);
  235.  
  236.                /* Destroy the memory device context        */
  237.  
  238. GpiAssociate(hpsBitmap,    (HDC)NULL);
  239.  
  240.                /* Destroy the presentation spaces used        */
  241. GpiDestroyPS(hpsBitmap);
  242. DevCloseDC(hDC);
  243.                /* Return the bitmap handle that    will be    used in    */
  244.                /* painting the image on    the window        */
  245. hbmROP = hbmConstruct;
  246. }
  247. #pragma    subtitle("   Module Purpose - Bitmap Sizing Function")
  248. #pragma    page( )
  249.  
  250. /* --- SizeBitmap -------------------------------------    [ Private ] ---    */
  251. /*                                    */
  252. /*     This function is    used to    size the scaled    bitmap for the window.    */
  253. /*                                    */
  254. /*     Upon Entry:                            */
  255. /*                                    */
  256. /*     HWND hWnd; = Window Handle                    */
  257. /*                                    */
  258. /*     Upon Exit:                            */
  259. /*                                    */
  260. /*     Nothing                                */
  261. /*                                    */
  262. /* --------------------------------------------------------------------    */
  263.  
  264. static VOID SizeBitmap(HWND hWnd)
  265.  
  266. {
  267. BITMAPINFOHEADER bmp;           /* Bitmap Information Header        */
  268. RECTL         rcl;           /* Window Rectangle            */
  269. LONG         cx;           /* Bitmap Width            */
  270. LONG         cy;           /* Bitmap Height            */
  271.  
  272. WinQueryWindowRect(hWnd, &rcl);
  273.  
  274. GpiQueryBitmapParameters(hbmView, &bmp);
  275.  
  276. cx = (bmp.cx * lScale) / 100L;
  277. cy = (bmp.cy * lScale) / 100L;
  278.  
  279. rclDest.xRight = (rclDest.xLeft      = ((rcl.xRight - rcl.xLeft) /    2L) - (cx / 2L)) + cx;
  280. rclDest.yTop   = (rclDest.yBottom = ((rcl.yTop - rcl.yBottom) /    2L) - (cy / 2L)) + cy;
  281.  
  282. rclImage.xRight    = (rclImage.xLeft   = ((rcl.xRight - rcl.xLeft)    / 2L) -    (bmp.cx    * 4L)) + bmp.cx    * 8L;
  283. rclImage.yTop    = (rclImage.yBottom = ((rcl.yTop - rcl.yBottom)    / 2L) -    (bmp.cy    * 4L)) + bmp.cy    * 8L;
  284.  
  285. rclImage.xLeft     -= 3L;
  286. rclImage.yBottom -= 3L;
  287. rclImage.xRight     += 3L;
  288. rclImage.yTop     += 3L;
  289.                /* Form the final boundary points        */
  290.  
  291. aptlArea[0].x =    rclDest.xLeft  - 2L;
  292. aptlArea[0].y =    rclDest.yTop   + 2L;
  293. aptlArea[1].x =    rclDest.xRight + 2L;
  294. aptlArea[1].y =    rclDest.yTop   + 2L;
  295.  
  296. aptlArea[2].x =    rclDest.xRight    + 2L;
  297. aptlArea[2].y =    rclDest.yBottom    - 2L;
  298. aptlArea[3].x =    rclDest.xLeft    - 2L;
  299. aptlArea[3].y =    rclDest.yBottom    - 2L;
  300.  
  301. aptlArea[4].x =    rclDest.xLeft  - 1L;
  302. aptlArea[4].y =    rclDest.yTop   + 1L;
  303. aptlArea[5].x =    rclDest.xRight + 1L;
  304. aptlArea[5].y =    rclDest.yTop   + 1L;
  305.  
  306. aptlArea[6].x =    rclDest.xRight    + 1L;
  307. aptlArea[6].y =    rclDest.yBottom    - 1L;
  308. aptlArea[7].x =    rclDest.xLeft    - 1L;
  309. aptlArea[7].y =    rclDest.yBottom    - 1L;
  310. }
  311. #pragma    subtitle("   Module Purpose - Bitmap Stack Sizing Function")
  312. #pragma    page( )
  313.  
  314. /* --- SizeBitmapStack --------------------------------    [ Private ] ---    */
  315. /*                                    */
  316. /*     This function is    used to    calculate the size and position    of    */
  317. /*     the bitmaps from    the bitmap array for the window.        */
  318. /*                                    */
  319. /*     Upon Entry:                            */
  320. /*                                    */
  321. /*     HWND hWnd; = Window Handle                    */
  322. /*                                    */
  323. /*     Upon Exit:                            */
  324. /*                                    */
  325. /*     Nothing                                */
  326. /*                                    */
  327. /* --------------------------------------------------------------------    */
  328.  
  329. static VOID SizeBitmapStack(HWND hWnd)
  330.  
  331. {
  332. BITMAPINFOHEADER bmp;           /* Bitmap Information Header        */
  333. RECTL         rcl;           /* Window Rectangle            */
  334. LONG         cx;           /* Bitmap Width            */
  335. LONG         cy;           /* Bitmap Height            */
  336. LONG         xImage;       /* Image Starting Point        */
  337. register INT i;               /* Loop Counter            */
  338.  
  339.  
  340. WinQueryWindowRect(hWnd, &rcl);
  341.     
  342. for ( i    = 0, cx    = 10 * (cBitmaps - 1), cy = 0L;    i < cBitmaps; i++ )
  343.    {
  344.    GpiQueryBitmapParameters(abm[i].hbm,    &bmp);
  345.  
  346.    cx += bmp.cx;
  347.    if (    bmp.cy > cy )
  348.        cy = bmp.cy;
  349.    }
  350.  
  351. rclImage.xRight    = (rclImage.xLeft   = ((rcl.xRight - rcl.xLeft)    / 2L) -    (cx / 2L)) + cx;
  352. rclImage.yTop    = (rclImage.yBottom = ((rcl.yTop - rcl.yBottom)    / 2L) -    (cy / 2L)) + cy;
  353.  
  354. xImage = rclImage.xLeft;
  355.  
  356. rclImage.xLeft     -= 3L;
  357. rclImage.yBottom -= 3L;
  358. rclImage.xRight     += 3L;
  359. rclImage.yTop     += 3L;
  360.  
  361. for ( i    = 0; i < cBitmaps; i++ )
  362.    {
  363.    GpiQueryBitmapParameters(abm[i].hbm,    &bmp);
  364.  
  365.    abm[i].rclDest.xRight = (abm[i].rclDest.xLeft   = xImage) + bmp.cx;
  366.    abm[i].rclDest.yTop     = (abm[i].rclDest.yBottom = ((rcl.yTop    - rcl.yBottom) / 2L) - (bmp.cy / 2L)) +    bmp.cy;
  367.  
  368.                /* Form the final boundary points        */
  369.  
  370.    abm[i].aptlArea[0].x    = abm[i].rclDest.xLeft    - 2L;
  371.    abm[i].aptlArea[0].y    = abm[i].rclDest.yTop    + 2L;
  372.    abm[i].aptlArea[1].x    = abm[i].rclDest.xRight    + 2L;
  373.    abm[i].aptlArea[1].y    = abm[i].rclDest.yTop    + 2L;
  374.  
  375.    abm[i].aptlArea[2].x    = abm[i].rclDest.xRight     + 2L;
  376.    abm[i].aptlArea[2].y    = abm[i].rclDest.yBottom - 2L;
  377.    abm[i].aptlArea[3].x    = abm[i].rclDest.xLeft     - 2L;
  378.    abm[i].aptlArea[3].y    = abm[i].rclDest.yBottom - 2L;
  379.  
  380.    abm[i].aptlArea[4].x    = abm[i].rclDest.xLeft    - 1L;
  381.    abm[i].aptlArea[4].y    = abm[i].rclDest.yTop    + 1L;
  382.    abm[i].aptlArea[5].x    = abm[i].rclDest.xRight    + 1L;
  383.    abm[i].aptlArea[5].y    = abm[i].rclDest.yTop    + 1L;
  384.  
  385.    abm[i].aptlArea[6].x    = abm[i].rclDest.xRight     + 1L;
  386.    abm[i].aptlArea[6].y    = abm[i].rclDest.yBottom - 1L;
  387.    abm[i].aptlArea[7].x    = abm[i].rclDest.xLeft     - 1L;
  388.    abm[i].aptlArea[7].y    = abm[i].rclDest.yBottom - 1L;
  389.  
  390.    xImage += (bmp.cx + 10L);
  391.    }
  392. }
  393. #pragma    subtitle("   Client Window - Client Window Procedure")
  394. #pragma    page( )
  395.  
  396. /* --- ROPsTestWndProc --------------------------------- [ Public ] ---    */
  397. /*                                    */
  398. /*     This function is    used to    process    the messages sent to the    */
  399. /*     applications client window.                    */
  400. /*                                    */
  401. /*     Upon Entry:                            */
  402. /*                                    */
  403. /*     HWND   hWnd; = Window Handle                    */
  404. /*     ULONG  msg;  = PM Message                    */
  405. /*     MPARAM mp1;  = Message Parameter    1                */
  406. /*     MPARAM mp2;  = Message Parameter    2                */
  407. /*                                    */
  408. /*     Upon Exit:                            */
  409. /*                                    */
  410. /*     ROPsTestWndProc = Message Handling Result            */
  411. /*                                    */
  412. /* --------------------------------------------------------------------    */
  413.  
  414. MRESULT    EXPENTRY ROPsTestWndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  415.  
  416. {
  417. CHAR            szTitle[300];  /* Title    Bar Text        */
  418. HPS            hPS;       /* Presentation Space Handle        */
  419. LONG            lClrBack;  /* Colour Holder            */
  420. LONG            lClrFore;  /* Colour Holder            */
  421. LONG            lScrollInc;/* Scroll Increment            */
  422. PBITMAPARRAYFILEHEADER    pbafh;       /* Bitmap Array File    Header Pointer    */
  423. PBITMAPARRAYFILEHEADER2    pbafh2;       /* Bitmap Array File    Header Pointer    */
  424. PBITMAPFILEHEADER    pbfh;       /* Bitmap File Header Pointer    */
  425. PBITMAPFILEHEADER2    pbfh2;       /* Bitmap File Header Pointer    */
  426. PBITMAPINFO        pbmi;       /* Bitmap Info Pointer        */
  427. PBITMAPINFO2        pbmi2;       /* Bitmap Info Pointer        */
  428. POINTL            ptl;       /* Pointer Position            */
  429. RECTL            rcl;       /* Window Rectangle            */
  430. register INT i;               /* Index                */
  431.  
  432. switch ( msg )
  433.    {
  434. /************************************************************************/
  435. /* Window being    created, perform window    initialization            */
  436. /************************************************************************/
  437.  
  438.    case    WM_CREATE :
  439.  
  440.        hptrWait     = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT,    FALSE);
  441.        hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW,    FALSE);
  442.  
  443.        cxScreen    = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  444.  
  445.        hmenuROPs = WinWindowFromID(WinQueryWindow(hWnd,    QW_PARENT), FID_MENU);
  446.        hwndHScroll = WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), FID_HORZSCROLL);
  447.        hwndVScroll = WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), FID_VERTSCROLL);
  448.  
  449.                /************************************************/
  450.                /* PDSGetTemplate is used to allow controls in  */
  451.                /* windows.  Do not remove this function    if you */
  452.                /* intend to include controls within the    window.*/
  453.                /************************************************/
  454.  
  455.        PDSGetTemplate(hWnd, WIN_ROPSTEST);
  456.        break;
  457.  
  458. /************************************************************************/
  459. /* Window being    sized                            */
  460. /************************************************************************/
  461.  
  462.    case    WM_SIZE    :
  463.        if ( cBitmaps )
  464.        SizeBitmapStack(hWnd);
  465.  
  466.        WinQueryWindowRect(hWnd,    &rcl);
  467.  
  468.        if ( (lHorzRange    = cxROP    - (cxWindow = rcl.xRight - rcl.xLeft)) < 0L )
  469.        {
  470.        lHorzRange =    0L;
  471.        rclROP.xLeft     = 0L;
  472.        rclROP.xRight = cxROP;
  473.        }
  474.        else
  475.        rclROP.xRight = rclROP.xLeft    + cxWindow;
  476.        if ( (lVertRange    = cyROP    - (cyWindow = rcl.yTop - rcl.yBottom)) < 0L )
  477.        {
  478.        lVertRange =    0L;
  479.        rclROP.yBottom  = 0L;
  480.        rclROP.yTop       = cyROP;
  481.        }
  482.        else
  483.        rclROP.yBottom = (rclROP.yTop = cyROP - lVertPos) - cyWindow;
  484.  
  485.        WinSendMsg(hwndVScroll, SBM_SETSCROLLBAR, MPFROMSHORT(lVertPos),
  486.           MPFROM2SHORT(0, lVertRange));
  487.        WinSendMsg(hwndVScroll, SBM_SETTHUMBSIZE, MPFROM2SHORT(cyWindow,    cyROP),    0L);
  488.  
  489.        WinSendMsg(hwndHScroll, SBM_SETSCROLLBAR, MPFROMSHORT(lHorzPos),
  490.           MPFROM2SHORT(0, lHorzRange));
  491.        WinSendMsg(hwndHScroll, SBM_SETTHUMBSIZE, MPFROM2SHORT(cxWindow,    cxROP),    0L);
  492.        WinInvalidateRect(hWnd, NULL, FALSE);
  493.        break;
  494.  
  495. /************************************************************************/
  496. /* Perform menu    initialization                        */
  497. /************************************************************************/
  498.  
  499.    case    WM_INITMENU :
  500.        switch (    SHORT1FROMMP(mp1) )
  501.        {
  502.        case    IDM_DISPLAY :
  503.            WinSendMsg(hmenuROPs, MM_SETITEMATTR, MPFROM2SHORT(IDM_BITMAPARRAY, TRUE),
  504.               MPFROM2SHORT(MIA_CHECKED, fBitmapArray ? MIA_CHECKED : 0));
  505.            WinSendMsg(hmenuROPs, MM_SETITEMATTR, MPFROM2SHORT(IDM_ROPARRAY,    TRUE),
  506.               MPFROM2SHORT(MIA_CHECKED, fBitmapArray ? 0 : MIA_CHECKED));
  507.            break;
  508.  
  509.        case    IDM_FILE :
  510.            break;
  511.  
  512.        }
  513.        break;
  514.  
  515. /************************************************************************/
  516. /* Process key press from keyboard                    */
  517. /************************************************************************/
  518.  
  519.    case    WM_CHAR    :
  520.        if ( CHARMSG(&msg)->fs &    KC_VIRTUALKEY )
  521.        switch ( CHARMSG(&msg)->vkey    )
  522.            {
  523.            case VK_PAGEUP :
  524.            WinSendMsg(hWnd, WM_VSCROLL,    MPFROMSHORT(FID_VERTSCROLL), MPFROM2SHORT(0, SB_PAGEUP));
  525.            return(0L);
  526.  
  527.            case VK_PAGEDOWN    :
  528.            WinSendMsg(hWnd, WM_VSCROLL,    MPFROMSHORT(FID_VERTSCROLL), MPFROM2SHORT(0, SB_PAGEDOWN));
  529.            return(0L);
  530.            }
  531.                /************************************************/
  532.                /* PDSKeyProc is    used to    allow controls in      */
  533.                /* windows.  Do not remove this function    if you */
  534.                /* intend to include controls within the    window.*/
  535.                /************************************************/
  536.  
  537.        return(PDSKeyProc(hWnd, msg, mp1, mp2));
  538.  
  539. /************************************************************************/
  540. /* Button 2 being depressed                        */
  541. /************************************************************************/
  542.  
  543.    case    WM_BUTTON2DOWN :
  544.        if ( !fBitmapArray && hbmROP )
  545.        {
  546.        lHorzPos = SHORT1FROMMR(WinSendMsg(hwndHScroll, SBM_QUERYPOS, 0L, 0L));
  547.        lVertPos = SHORT1FROMMR(WinSendMsg(hwndVScroll, SBM_QUERYPOS, 0L, 0L));
  548.  
  549.        lRop    = (lVertPos + (cyWindow    - SHORT2FROMMP(mp1))) /    cyImage    * 16 + (lHorzPos + SHORT1FROMMP(mp1)) /    cxImage;
  550.        WinDlgBox(HWND_DESKTOP, hwndROPsFrame, (PFNWP)ViewROPDlgProc,
  551.              (HMODULE)NULL, DLG_VIEWROP, NULL);
  552.        }
  553.        break;
  554.  
  555. /************************************************************************/
  556. /* Process vertical scroll requests                    */
  557. /************************************************************************/
  558.  
  559.    case    WM_VSCROLL :
  560.        lVertPos    = SHORT1FROMMR(WinSendMsg(hwndVScroll, SBM_QUERYPOS, 0L, 0L));
  561.        switch (    HIUSHORT(mp2) )
  562.        {
  563.        case    SB_LINEUP :
  564.            lScrollInc = -cyImage;
  565.            break;
  566.  
  567.        case    SB_LINEDOWN :
  568.            lScrollInc = cyImage;
  569.            break;
  570.  
  571.        case    SB_PAGEUP :
  572.            lScrollInc = -cyWindow;
  573.            break;
  574.  
  575.        case    SB_PAGEDOWN :
  576.            lScrollInc = cyWindow;
  577.            break;
  578.  
  579.        case    SB_SLIDERPOSITION :
  580.        case    SB_SLIDERTRACK :
  581.            lScrollInc = SHORT1FROMMP(mp2) -    lVertPos;
  582.            break;
  583.  
  584.        default :
  585.            return(0L);
  586.        }
  587.  
  588.        if ( lScrollInc = max(-lVertPos,    min(lScrollInc,    lVertRange - lVertPos))    )
  589.        {
  590.        rclROP.yBottom = (rclROP.yTop = cyROP - (lVertPos +=    lScrollInc)) - cyWindow;
  591.        WinInvalidateRect(hWnd, NULL, FALSE);
  592.        WinSendMsg(hwndVScroll, SBM_SETPOS, MPFROM2SHORT(lVertPos, 0), 0L);
  593.        }
  594.        break;
  595.  
  596. /************************************************************************/
  597. /* Process horizontal scroll requests                    */
  598. /************************************************************************/
  599.  
  600.    case    WM_HSCROLL :
  601.        lHorzPos    = SHORT1FROMMR(WinSendMsg(hwndHScroll, SBM_QUERYPOS, 0L, 0L));
  602.        switch (    HIUSHORT(mp2) )
  603.        {
  604.        case    SB_LINELEFT :
  605.            lScrollInc = -cxImage;
  606.            break;
  607.  
  608.        case    SB_LINERIGHT :
  609.            lScrollInc = cxImage;
  610.            break;
  611.  
  612.        case    SB_PAGELEFT :
  613.            lScrollInc = -cxWindow;
  614.            break;
  615.  
  616.        case    SB_PAGERIGHT :
  617.            lScrollInc = cxWindow;
  618.            break;
  619.  
  620.        case    SB_SLIDERPOSITION :
  621.        case    SB_SLIDERTRACK :
  622.            lScrollInc = SHORT1FROMMP(mp2) -    lHorzPos;
  623.            break;
  624.  
  625.        default :
  626.            return(0L);
  627.        }
  628.  
  629.        if ( lScrollInc = max(-lHorzPos,    min(lScrollInc,    lHorzRange - lHorzPos))    )
  630.        {
  631.        rclROP.xRight = (rclROP.xLeft = (lHorzPos +=    lScrollInc)) + cxWindow;
  632.        WinInvalidateRect(hWnd, NULL, FALSE);
  633.        WinSendMsg(hwndHScroll, SBM_SETPOS, MPFROM2SHORT(lHorzPos, 0), 0L);
  634.        }
  635.        break;
  636.  
  637. /************************************************************************/
  638. /* Process control selections                        */
  639. /************************************************************************/
  640.  
  641.    case    WM_CONTROL :
  642.        switch (    SHORT2FROMMP(mp1) )
  643.        {
  644.        }
  645.        break;
  646.  
  647. /************************************************************************/
  648. /* Process menu    and button selections                    */
  649. /************************************************************************/
  650.  
  651.    case    WM_COMMAND :
  652.        switch (    SHORT1FROMMP(mp1) )
  653.        {
  654.        case    IDM_OPTIONS :
  655.            if ( WinDlgBox(HWND_DESKTOP, hwndROPsFrame, (PFNWP)OptionsDlgProc,
  656.                   (HMODULE)NULL, DLG_OPTIONS, NULL)    )
  657.            {
  658.            WinSetPointer(HWND_DESKTOP, hptrWait);
  659.            CreateROPBitmap(hWnd);
  660.            WinInvalidateRect(hWnd, NULL, FALSE);
  661.            WinSetPointer(HWND_DESKTOP, hptrArrow);
  662.            }
  663.            break;
  664.        case    IDM_OPEN :
  665.            if ( WinDlgBox(HWND_DESKTOP, hwndROPsFrame, (PFNWP)OpenBitmapDlgProc,
  666.                   (HMODULE)NULL, DLG_OPENBITMAP, NULL) )
  667.            {
  668.            WinSetPointer(HWND_DESKTOP, hptrWait);
  669.            hbmView = hbmGetBitmap(szBitmapFile);
  670.            SizeBitmap(hWnd);
  671.            if (    cBitmaps )
  672.                SizeBitmapStack(hWnd);
  673.            CreateROPBitmap(hWnd);
  674.            WinInvalidateRect(hWnd, NULL, FALSE);
  675.            strcat(memcpy(szTitle, "Bitmap Viewer - ", 17), szBitmapFile);
  676.            if (    fWindowsBitmap )
  677.                strcat(szTitle, " [Windows 3.x format]");
  678.            else
  679.                if ( f20Bitmap )
  680.                strcat(szTitle, " [OS/2 2.x format]");
  681.                else
  682.                strcat(szTitle, " [OS/2 1.x format]");
  683.            WinSetWindowText(hwndROPsFrame, szTitle);
  684.            WinSetPointer(HWND_DESKTOP, hptrArrow);
  685.            }
  686.            break;
  687.  
  688.        case    IDM_ROPARRAY :
  689.            fBitmapArray = FALSE;
  690.            WinInvalidateRect(hWnd, NULL, FALSE);
  691.            break;
  692.  
  693.        case    IDM_BITMAPARRAY    :
  694.            fBitmapArray = TRUE;
  695.            WinInvalidateRect(hWnd, NULL, FALSE);
  696.            break;
  697.        }
  698.        break;
  699.  
  700. /************************************************************************/
  701. /* Erase window    background                        */
  702. /************************************************************************/
  703.  
  704.    case    WM_ERASEBACKGROUND :
  705.        WinQueryWindowRect(hWnd,    &rcl);
  706.        WinFillRect((HPS)LONGFROMMP(mp1), &rcl, CLR_PALEGRAY);
  707.        break;
  708.  
  709. /************************************************************************/
  710. /* Paint client    window                            */
  711. /************************************************************************/
  712.  
  713.    case    WM_PAINT :
  714.        GpiCreateLogColorTable(hPS = WinBeginPaint(hWnd,    (HPS)NULL, &rcl), 0UL, LCOLF_RGB, 0L, 0L, (PLONG)NULL);
  715.  
  716.                /* Display the bitmap array images side-by-side    */
  717.        if ( fBitmapArray )
  718.        {
  719.        WinFillRect(hPS, &rcl, RGBCLR_PALEGRAY);
  720.        for ( i = 0;    i < cBitmaps; i++ )
  721.            {
  722.                /* Check    to see if the image is a 2-colour which    */
  723.                /* menas    that the colours have to be set        */
  724.                /* explicitely                    */
  725.  
  726.            if ( abm[i].cColours == 2L )
  727.            {
  728.            lClrBack = lClrFore = 0L;
  729.  
  730.                /* Check    to see if a 2.x    format bitmap since the    */
  731.                /* the structures are slightly different        */
  732.  
  733.            if (    f20Bitmap )
  734.                {
  735.                /* Locate the bitmap information    structure    */
  736.  
  737.                if ( (cBitmaps == 1) && !fBitmapArray )
  738.                {
  739.                pbfh2 = (PBITMAPFILEHEADER2)abm[i].pb;
  740.                pbmi2 = (PBITMAPINFO2)&pbfh2->bmp2;
  741.                }
  742.                else
  743.                {
  744.                pbafh2 = (PBITMAPARRAYFILEHEADER2)abm[i].pb;
  745.                pbmi2 = (PBITMAPINFO2)&pbafh2->bfh2.bmp2;
  746.                }
  747.                /* Transfer the RGB info to the colour    */
  748.                /* holders                    */
  749.  
  750.                memcpy(&lClrBack, &pbmi2->argbColor[0], 3);
  751.                memcpy(&lClrFore, &pbmi2->argbColor[1], 3);
  752.                }
  753.            else
  754.                {
  755.                /* Locate the bitmap information    structure    */
  756.  
  757.                if ( (cBitmaps == 1) && !fBitmapArray )
  758.                {
  759.                pbfh    = (PBITMAPFILEHEADER)abm[i].pb;
  760.                pbmi    = (PBITMAPINFO)&pbfh->bmp;
  761.                }
  762.                else
  763.                {
  764.                pbafh = (PBITMAPARRAYFILEHEADER)abm[i].pb;
  765.                pbmi    = (PBITMAPINFO)&pbafh->bfh.bmp;
  766.                }
  767.                /* Transfer the RGB info to the colour    */
  768.                /* holders                    */
  769.  
  770.                memcpy(&lClrBack, &pbmi->argbColor[0], 3);
  771.                memcpy(&lClrFore, &pbmi->argbColor[1], 3);
  772.                }
  773.                /* Draw the 2-colour    bitmap using the    */
  774.                /* provided colours from the    bitmap        */
  775.  
  776.            WinDrawBitmap(hPS, abm[i].hbm, (PRECTL)NULL,    (PPOINTL)(PVOID)&abm[i].rclDest,
  777.                  lClrFore, lClrBack, DBM_NORMAL);
  778.            }
  779.            else
  780.                /* Draw the bitmap from the array        */
  781.  
  782.            WinDrawBitmap(hPS, abm[i].hbm, (PRECTL)NULL,    (PPOINTL)(PVOID)&abm[i].rclDest,
  783.                  RGB_WHITE, RGB_BLACK, DBM_NORMAL);
  784.  
  785.                /* Draw the 3-D frame around    the image    */
  786.  
  787.            GpiSetColor(hPS,    RGBCLR_SHADOW);
  788.            GpiMove(hPS, &abm[i].aptlArea[7]);
  789.            GpiPolyLine(hPS,    2L, &abm[i].aptlArea[4]);
  790.  
  791.            GpiSetColor(hPS,    RGB_WHITE);
  792.            GpiPolyLine(hPS,    2L, &abm[i].aptlArea[6]);
  793.  
  794.            GpiSetColor(hPS,    RGB_BLACK);
  795.            GpiMove(hPS, &abm[i].aptlArea[3]);
  796.            GpiPolyLine(hPS,    2L, &abm[i].aptlArea[0]);
  797.  
  798.            GpiSetColor(hPS,    RGBCLR_PALEGRAY);
  799.            GpiPolyLine(hPS,    2L, &abm[i].aptlArea[2]);
  800.            }
  801.        }
  802.        else
  803.        {
  804.        if (    (rclROP.xRight < cxWindow) || (rclROP.yTop < cyWindow) )
  805.            WinFillRect(hPS,    &rcl, RGBCLR_PALEGRAY);
  806.        ptl.x = ptl.y = 0L;
  807.        WinDrawBitmap(hPS, hbmROP, &rclROP, &ptl, 0L, 0L, DBM_NORMAL);
  808.        }
  809.        WinEndPaint(hPS);
  810.        break;
  811.  
  812. /************************************************************************/
  813. /* Window being    destroyed, perform clean-up operations            */
  814. /************************************************************************/
  815.  
  816.    case    WM_DESTROY :
  817.        for ( i = 0; i <    cBitmaps; i++ )
  818.        GpiDeleteBitmap(abm[i].hbm);
  819.  
  820.        if ( hbmROP )
  821.        GpiDeleteBitmap(hbmROP);
  822.  
  823.        if ( pb )
  824.        free(pb);
  825.        break;
  826.  
  827.             /* Default message processing            */
  828.    default :
  829.        return(WinDefWindowProc(hWnd, msg, mp1, mp2));
  830.    }
  831. return(0L);
  832. }
  833.