home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bmp4.zip / VIEWDLG.C < prev    next >
C/C++ Source or Header  |  1995-11-24  |  23KB  |  688 lines

  1. #pragma    title("Icon/Pointer Viewer  --  Version 1  --  (ViewDlg.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 <os2.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. #include "appdefs.h"
  13. #include "makeptr.h"
  14.  
  15. /* This    module contains    routine    used to    create the defined pointer    */
  16. /* and test its    appearance.                        */
  17.  
  18. /* Filename:   ViewDlg.C                        */
  19.  
  20. /*  Version:   1                            */
  21. /*  Created:   1995-11-06                        */
  22. /*  Revised:   1995-11-24                        */
  23.  
  24. /* Routines:   VOID CreateMask(LONG cx,    LONG cy);            */
  25. /*           VOID CreateBackgroundBitmap(VOID);            */
  26. /*           VOID DestroyBackgroundBitmap(VOID);            */
  27. /*           VOID SaveBackground(HWND    hWnd);                */
  28. /*           VOID RestoreBackground(VOID);                */
  29. /*           VOID BuildMaskImage(VOID);                */
  30. /*           MRESULT EXPENTRY    ViewDlgProc(HWND hWnd, ULONG msg,    */
  31. /*                        MPARAM mp1,    MPARAM mp2);    */
  32.  
  33.  
  34. /************************************************************************/
  35. /************************************************************************/
  36. /************************************************************************/
  37. /* DISCLAIMER OF WARRANTIES:                        */
  38. /* -------------------------                        */
  39. /* The following [enclosed] code is sample code    created    by IBM        */
  40. /* Corporation and Prominare Inc.  This    sample code is not part    of any    */
  41. /* standard IBM    product    and is provided    to you solely for the purpose    */
  42. /* of assisting    you in the development of your applications.  The code    */
  43. /* is provided "AS IS",    without    warranty of any    kind.  Neither IBM nor    */
  44. /* Prominare shall be liable for any damages arising out of your    */
  45. /* use of the sample code, even    if they    have been advised of the    */
  46. /* possibility of such damages.                        */
  47. /************************************************************************/
  48. /************************************************************************/
  49. /************************************************************************/
  50. /*               D I S C L A I M E R                */
  51. /* This    code is    provided on an as is basis with    no implied support.    */
  52. /* It should be    considered freeware that cannot    be rebundled as        */
  53. /* part    of a larger "*ware" offering without our consent.        */
  54. /************************************************************************/
  55. /************************************************************************/
  56. /************************************************************************/
  57.  
  58. /* Copyright ╕ International Business Machines Corp., 1995.        */
  59. /* Copyright ╕ 1995  Prominare Inc.  All Rights    Reserved.        */
  60.  
  61. /* --------------------------------------------------------------------    */
  62.  
  63.  
  64. POINTL         ptlMask;
  65. POINTL         ptlImage;
  66. POINTL         ptlMouse;
  67. POINTL         ptlBackground;
  68.  
  69. HBITMAP         hbmXOR;
  70. HBITMAP         hbmImage;
  71. HBITMAP         hbmMask;
  72. HBITMAP         hbmBackground;
  73.  
  74. HDC hDC;               /* Screen Device Context Handle    */
  75. HPS hpsMem;               /* Memory Presentation Space    Handle    */
  76. HPS hpsDesktop;               /* Desktop Presentation Space Handle    */
  77.  
  78. POINTL         aptlBackground[4];/* Background Display Points        */
  79. POINTL         aptlImage[4];       /* Image Pointer Display Points    */
  80. POINTL         aptlSource[3];       /* Bitmap Region Points Array    */
  81. BITMAPINFOHEADER2 bmInfo;       /* Bitmap Information Header        */
  82. LONG          alBmpFormats[2]; /* Bitmap Formats Array        */
  83.  
  84. BOOL         fTest = FALSE;
  85.  
  86. /* --- Module Prototype    Definitions -----------------------------------    */
  87.  
  88. VOID CreateMask(LONG cx, LONG cy);
  89. VOID CreateBackgroundBitmap(VOID);
  90. VOID DestroyBackgroundBitmap(VOID);
  91. VOID SaveBackground(HWND hWnd);
  92. VOID RestoreBackground(VOID);
  93. VOID BuildMaskImage(VOID);
  94.  
  95. #pragma    subtitle("   View Images - Mask Creation Function")
  96. #pragma    page( )
  97.  
  98. /* --- CreateMask -------------------------------------- [ Public ] ---    */
  99. /*                                    */
  100. /*     This function is    used to    create the necessary black and white    */
  101. /*     AND and XOR mask.                        */
  102. /*                                    */
  103. /*     Upon Entry:                            */
  104. /*                                    */
  105. /*     LONG cx;    = Image    Width                        */
  106. /*     LONG cy;    = Image    Height                        */
  107. /*                                    */
  108. /*     Upon Exit:                            */
  109. /*                                    */
  110. /*     Nothing                                */
  111. /*                                    */
  112. /* --------------------------------------------------------------------    */
  113.  
  114. VOID CreateMask(LONG cx, LONG cy)
  115.  
  116. {
  117. SIZEL  sizl;               /* Size Holder            */
  118. POINTL aptl[4];               /* Bitmap Region Points Array    */
  119.  
  120.                /* Set the width    and height of the mask bitmap    */
  121. sizl.cx    = cx;
  122. sizl.cy    = cy * 2;
  123.                /* Open the device context and create a memory    */
  124.                /* DC for the bitmap                */
  125.  
  126. if ( !(hDC = DevOpenDC(hAB, OD_MEMORY, "*", 0L,    (PDEVOPENDATA)NULL, (HDC)NULL))    )
  127.    {
  128.    WinMessageBox(HWND_DESKTOP, hwndMakePtr, "Cannot open memory DC",
  129.          "Pointer Creation Tool", 0UL, MB_OK | MB_ICONHAND | MB_MOVEABLE);
  130.    return;
  131.    }
  132. else
  133.    if (    !(hpsMem = GpiCreatePS(hAB, hDC, &sizl,    PU_PELS    | GPIT_MICRO | GPIA_ASSOC)) )
  134.        {
  135.        DevCloseDC(hDC);
  136.        WinMessageBox(HWND_DESKTOP, hwndMakePtr,    "Cannot open memory PS",
  137.              "Pointer Creation Tool", 0UL, MB_OK | MB_ICONHAND | MB_MOVEABLE);
  138.        return;
  139.        }
  140.                /* Get the bitmap formats for the current    */
  141.                /* display.  This will allow the    code to    work    */
  142.                /* on any display                */
  143.  
  144. GpiQueryDeviceBitmapFormats(hpsMem, 2L,    alBmpFormats);
  145.  
  146.                /* Initialize the bitmap    header information for    */
  147.                /* the window/dialogue being copied to the    */
  148.                /* clipboard                    */
  149.  
  150. memset(&bmInfo,    0, sizeof(BITMAPINFOHEADER2));
  151. bmInfo.cbFix     = sizeof(BITMAPINFOHEADER2);
  152. bmInfo.cx     = (ULONG)cx;
  153. bmInfo.cy     = (ULONG)cy * 2;
  154. bmInfo.cPlanes     = (USHORT)alBmpFormats[0];
  155. bmInfo.cBitCount = (USHORT)1;
  156.  
  157.                /* Create the bitmap for    the XOR/AND mask and    */
  158.                /* set the bitmap created as the    current    bitmap    */
  159.  
  160. GpiSetBitmap(hpsMem, hbmMask = GpiCreateBitmap(hpsMem, &bmInfo,    0L, NULL, NULL));
  161.  
  162. memset(aptl, 0,    sizeof(POINTL) * 4);
  163.  
  164. aptl[3].x = (aptl[1].x = cx) + 1L;
  165. aptl[3].y = (aptl[1].y = cy) + 1L;
  166.  
  167. GpiSetColor(hpsMem, CLR_WHITE);
  168. GpiSetBackColor(hpsMem,    CLR_BLACK);
  169.  
  170. GpiWCBitBlt(hpsMem, hbmXOR, 4L,    aptl, ROP_ZERO,    BBO_OR);
  171.  
  172. aptl[0].y = cy;
  173. aptl[1].y = cy << 1UL;
  174.  
  175. GpiSetBackColor(hpsMem,    CLR_WHITE);
  176. GpiSetColor(hpsMem, CLR_BLACK);
  177.  
  178. GpiWCBitBlt(hpsMem, hbmXOR, 4L,    aptl, ROP_SRCCOPY, BBO_OR);
  179.  
  180.                /* Set the memory bitmap    as the current bitmap    */
  181.  
  182. GpiSetBitmap(hpsMem, (HBITMAP)NULL);
  183.  
  184.                /* Destroy the memory device context        */
  185.  
  186. GpiAssociate(hpsMem, (HDC)NULL);
  187. DevCloseDC(hDC);
  188.                /* Destroy the presentation spaces used        */
  189. GpiDestroyPS(hpsMem);
  190.  
  191. }
  192. #pragma    subtitle("   View Images - Background Bitmap Create Function")
  193. #pragma    page( )
  194.  
  195. /* --- CreateBackgroundBitmap -------------------------- [ Public ] ---    */
  196. /*                                    */
  197. /*     This function is    used to    create the bitmap that will contain    */
  198. /*     the background bitmap image.                    */
  199. /*                                    */
  200. /*     Upon Entry:                            */
  201. /*                                    */
  202. /*     Nothing                                */
  203. /*                                    */
  204. /*     Upon Exit:                            */
  205. /*                                    */
  206. /*     Nothing                                */
  207. /*                                    */
  208. /* --------------------------------------------------------------------    */
  209.  
  210. VOID CreateBackgroundBitmap(VOID)
  211.  
  212. {
  213. SIZEL  sizl;               /* Size Holder            */
  214.  
  215.                /* Initialize the background bitmap display    */
  216.                /* points                    */
  217.  
  218. memset(aptlBackground, 0, sizeof(POINTL) * 4UL);
  219. aptlBackground[3].x = abm[iBitmap].cx +    2;
  220. aptlBackground[3].y = abm[iBitmap].cy +    2;
  221.  
  222.                /* Initialize the size of the bitmap        */
  223.  
  224. sizl.cx    = abm[iBitmap].cx + 1L;
  225. sizl.cy    = abm[iBitmap].cy + 1L;
  226.  
  227.                /* Initialize the bitmap    header information for    */
  228.                /* the background bitmap    image            */
  229.  
  230. memset(&bmInfo,    0, sizeof(BITMAPINFOHEADER2));
  231. bmInfo.cbFix     = sizeof(BITMAPINFOHEADER2);
  232. bmInfo.cx     = (ULONG)abm[iBitmap].cx;
  233. bmInfo.cy     = (ULONG)abm[iBitmap].cy;
  234. bmInfo.cPlanes     = (USHORT)alBmpFormats[0];
  235. bmInfo.cBitCount = (USHORT)alBmpFormats[1];
  236.  
  237.                /* Open the device context and create a memory    */
  238.                /* DC for the bitmap                */
  239.  
  240. if ( !(hDC = DevOpenDC(hAB, OD_MEMORY, "*", 0L,    (PDEVOPENDATA)NULL, (HDC)NULL))    )
  241.    {
  242.    WinMessageBox(HWND_DESKTOP, hwndMakePtr, "Cannot open memory DC",
  243.          "Pointer Creation Tool", 0UL, MB_OK | MB_ICONHAND | MB_MOVEABLE);
  244.    return;
  245.    }
  246. else
  247.    if (    !(hpsMem = GpiCreatePS(hAB, hDC, &sizl,    PU_PELS    | GPIT_MICRO | GPIA_ASSOC)) )
  248.        {
  249.        DevCloseDC(hDC);
  250.        WinMessageBox(HWND_DESKTOP, hwndMakePtr,    "Cannot open memory PS",
  251.              "Pointer Creation Tool", 0UL, MB_OK | MB_ICONHAND | MB_MOVEABLE);
  252.        return;
  253.        }
  254.                /* Create the bitmap for    the background and    */
  255.                /* set the bitmap created as the    current    bitmap    */
  256.  
  257. hbmBackground =    GpiCreateBitmap(hpsMem,    &bmInfo, 0L, NULL, NULL);
  258.  
  259.                /* Initialize the source    points            */
  260. aptlSource[0].x    =
  261. aptlSource[0].y    = 0L;
  262. aptlSource[1].x    = abm[iBitmap].cx;
  263. aptlSource[1].y    = abm[iBitmap].cy;
  264.  
  265.                /* Get the PS for the desktop since this    is    */
  266.                /* used to capture and restore the background    */
  267.                /* bitmap area                    */
  268.  
  269. hpsDesktop = WinGetScreenPS(HWND_DESKTOP);
  270.  
  271. }
  272. #pragma    subtitle("   View Images - Background Bitmap Destroy Function")
  273. #pragma    page( )
  274.  
  275. /* --- DestroyBackgroundBitmap ------------------------- [ Public ] ---    */
  276. /*                                    */
  277. /*     This function is    used to    destroy    the bitmap that    contains    */
  278. /*     the background bitmap image.                    */
  279. /*                                    */
  280. /*     Upon Entry:                            */
  281. /*                                    */
  282. /*     Nothing                                */
  283. /*                                    */
  284. /*     Upon Exit:                            */
  285. /*                                    */
  286. /*     Nothing                                */
  287. /*                                    */
  288. /* --------------------------------------------------------------------    */
  289.  
  290. VOID DestroyBackgroundBitmap(VOID)
  291.  
  292. {
  293.                /* Restore the background area            */
  294. RestoreBackground( );
  295.                /* Destroy the memory device context        */
  296.  
  297. GpiAssociate(hpsMem, (HDC)NULL);
  298. DevCloseDC(hDC);
  299.                /* Destroy the presentation spaces used        */
  300. GpiDestroyPS(hpsMem);
  301. WinReleasePS(hpsDesktop);
  302.                /* Delete the bitmap                */
  303.  
  304. GpiDeleteBitmap(hbmBackground);
  305. }
  306. #pragma    subtitle("   View Images - Save Background Function")
  307. #pragma    page( )
  308.  
  309. /* --- SaveBackground ---------------------------------- [ Public ] ---    */
  310. /*                                    */
  311. /*     This function is    used to    copy the background where the pointer    */
  312. /*     will be displayed.  When    the pointer moves to a new location,    */
  313. /*     the old background will be refreshed using the captured image.    */
  314. /*                                    */
  315. /*     Upon Entry:                            */
  316. /*                                    */
  317. /*     HWND hWnd; = Dialogue Window Handle                */
  318. /*                                    */
  319. /*     Upon Exit:                            */
  320. /*                                    */
  321. /*     Nothing                                */
  322. /*                                    */
  323. /* --------------------------------------------------------------------    */
  324.  
  325. VOID SaveBackground(HWND hWnd)
  326.  
  327. {
  328.                /* Map the target window/dialogue points    to the    */
  329.                /* screen desktop                */
  330.  
  331. WinMapWindowPoints(hWnd, HWND_DESKTOP, &ptlBackground, 1L);
  332. aptlBackground[1].x = (aptlBackground[0].x = aptlSource[2].x = ptlBackground.x)    + (aptlBackground[3].x - 1L);
  333. aptlBackground[1].y = (aptlBackground[0].y = aptlSource[2].y = ptlBackground.y)    + (aptlBackground[3].y - 1L);
  334.  
  335.                /* Set the background bitmap as the current    */
  336.                /* bitmap                    */
  337.  
  338. GpiSetBitmap(hpsMem, hbmBackground);
  339.  
  340.                /* Copy the background area to the bitmap    */
  341.  
  342. GpiBitBlt(hpsMem, hpsDesktop, 3L, aptlSource, ROP_SRCCOPY, BBO_IGNORE);
  343.  
  344.                /* Set the memory bitmap    as the current bitmap    */
  345.  
  346. GpiSetBitmap(hpsMem, (HBITMAP)NULL);
  347.  
  348. }
  349. #pragma    subtitle("   View Images - Restore Background Function")
  350. #pragma    page( )
  351.  
  352. /* --- RestoreBackground ------------------------------- [ Public ] ---    */
  353. /*                                    */
  354. /*     This function is    used to    copy the background where the pointer    */
  355. /*     will be displayed.  When    the pointer moves to a new location,    */
  356. /*     the old background will be refreshed using the captured image.    */
  357. /*                                    */
  358. /*     Upon Entry:                            */
  359. /*                                    */
  360. /*     Nothing                                */
  361. /*                                    */
  362. /*     Upon Exit:                            */
  363. /*                                    */
  364. /*     Nothing                                */
  365. /*                                    */
  366. /* --------------------------------------------------------------------    */
  367.  
  368. VOID RestoreBackground(VOID)
  369.  
  370. {
  371.  
  372. GpiWCBitBlt(hpsDesktop,    hbmBackground, 4L, aptlBackground, ROP_SRCCOPY,    BBO_IGNORE);
  373.  
  374. }
  375. #pragma    subtitle("   View Images - Bitmap Mask Build Function")
  376. #pragma    page( )
  377.  
  378. /* --- hbmBuildMask ------------------------------------ [ Public ] ---    */
  379. /*                                    */
  380. /*     This function is    used to    build the AND/XOR mask along with the    */
  381. /*     final colour image bitmap.                    */
  382. /*                                    */
  383. /*     Upon Entry:                            */
  384. /*                                    */
  385. /*     Nothing                                */
  386. /*                                    */
  387. /*     Upon Exit:                            */
  388. /*                                    */
  389. /*     Nothing                                */
  390. /*                                    */
  391. /* --------------------------------------------------------------------    */
  392.  
  393. VOID BuildMaskImage(VOID)
  394.  
  395. {
  396. HPS            hPS;       /* Presentation Space Handle        */
  397. PBITMAPARRAYFILEHEADER    pbafh;       /* Bitmap Array File    Header Pointer    */
  398. PBITMAPARRAYFILEHEADER2    pbafh2;       /* Bitmap Array File    Header Pointer    */
  399. PBITMAPFILEHEADER    pbfh;       /* Bitmap Array File    Header Pointer    */
  400. PBITMAPFILEHEADER2    pbfh2;       /* Bitmap Array File    Header Pointer    */
  401. PBITMAPINFO        pbmi;       /* Bitmap Info Pointer        */
  402. PBITMAPINFO2        pbmi2;       /* Bitmap Info Pointer        */
  403. RGB            rgbBlack;  /* Black RGB                */
  404. RGB2            rgb2Black; /* Black RGB                */
  405. RGB2            rgb2White; /* White RGB                */
  406. register INT i;               /* Loop Counter            */
  407.  
  408.                /* Check    to make    sure that the bitmap is    using    */
  409.                /* a colour table since bitmaps with more than    */
  410.                /* 256 colours use the actual bits of the image    */
  411.                /* to describe the colour            */
  412.  
  413. if ( abm[iBitmap].cColours <= 256L )
  414.    {
  415.                /* Check    to see if the image is a OS/2 2.x    */
  416.                /* format                    */
  417.    if (    f20Bitmap )
  418.        {
  419.                /* Check    to see if the bitmap is    an array and    */
  420.                /* depending on type, use appropriate        */
  421.                /* structures to    locate the RGB table        */
  422.  
  423.        if ( (cBitmaps == 1) && !fBitmapArray )
  424.        {
  425.        pbfh2 = (PBITMAPFILEHEADER2)abm[iBitmap].pb;
  426.        memcpy(pbmi2    = (PBITMAPINFO2)malloc(sizeof(BITMAPINFOHEADER2) + abm[iBitmap].cColours * sizeof(RGB2)),
  427.           &pbfh2->bmp2,    sizeof(BITMAPINFOHEADER2) + abm[iBitmap].cColours * sizeof(RGB2));
  428.        }
  429.        else
  430.        {
  431.        pbafh2 = (PBITMAPARRAYFILEHEADER2)abm[iBitmap].pb;
  432.        memcpy(pbmi2    = (PBITMAPINFO2)malloc(sizeof(BITMAPINFOHEADER2) + abm[iBitmap].cColours * sizeof(RGB2)),
  433.           &pbafh2->bfh2.bmp2, sizeof(BITMAPINFOHEADER2)    + abm[iBitmap].cColours    * sizeof(RGB2));
  434.        }
  435.        rgb2White.bRed =    rgb2White.bBlue    = rgb2White.bGreen = (BYTE)0xff;
  436.        rgb2Black.bRed =    rgb2Black.bBlue    = rgb2Black.bGreen = (BYTE)0x00;
  437.        rgb2Black.fcOptions = rgb2White.fcOptions = (BYTE)0x00;
  438.  
  439.        pbmi2->argbColor[iClr] =    rgb2Black;
  440.  
  441.        hbmImage    = GpiCreateBitmap(hPS =    WinGetPS(HWND_DESKTOP),    (PBITMAPINFOHEADER2)pbmi2, CBM_INIT, abm[iBitmap].pbImage, pbmi2);
  442.        for ( i = 0; i <    (INT)abm[iBitmap].cColours; i++    )
  443.        pbmi2->argbColor[i] = rgb2White;
  444.        pbmi2->argbColor[iClr] =    rgb2Black;
  445.        hbmXOR =    GpiCreateBitmap(hPS, (PBITMAPINFOHEADER2)pbmi2,    CBM_INIT, abm[iBitmap].pbImage,    pbmi2);
  446.  
  447.        WinReleasePS(hPS);
  448.        free(pbmi2);
  449.        }
  450.    else
  451.                /* Image    a OS/2 1.x format, use the appropriate    */
  452.                /* structures                    */
  453.        {
  454.                /* Check    to see if the bitmap is    an array and    */
  455.                /* depending on type, use appropriate        */
  456.                /* structures to    locate the RGB table        */
  457.  
  458.        if ( (cBitmaps == 1) && !fBitmapArray )
  459.        {
  460.        pbfh    = (PBITMAPFILEHEADER)abm[iBitmap].pb;
  461.        memcpy(pbmi = (PBITMAPINFO)malloc(sizeof(BITMAPINFOHEADER) +    abm[iBitmap].cColours *    sizeof(RGB)),
  462.           &pbfh->bmp, sizeof(BITMAPINFOHEADER) + abm[iBitmap].cColours * sizeof(RGB));
  463.        }
  464.        else
  465.        {
  466.        pbafh = (PBITMAPARRAYFILEHEADER)abm[iBitmap].pb;
  467.        memcpy(pbmi = (PBITMAPINFO)malloc(sizeof(BITMAPINFOHEADER) +    abm[iBitmap].cColours *    sizeof(RGB)),
  468.           &pbafh->bfh.bmp, sizeof(BITMAPINFOHEADER) + abm[iBitmap].cColours * sizeof(RGB));
  469.        }
  470.  
  471.        rgbBlack.bRed = rgbBlack.bBlue =    rgbBlack.bGreen    = (BYTE)0x00;
  472.  
  473.        pbmi->argbColor[iClr] = rgbBlack;
  474.  
  475.        hbmImage    = GpiCreateBitmap(hPS =    WinGetPS(HWND_DESKTOP),    (PBITMAPINFOHEADER2)pbmi, CBM_INIT, abm[iBitmap].pbImage,
  476.                   (PBITMAPINFO2)pbmi);
  477.  
  478.        memset(pbmi->argbColor, 0xff, abm[iBitmap].cColours * sizeof(RGB));
  479.        pbmi->argbColor[iClr] = rgbBlack;
  480.        hbmXOR =    GpiCreateBitmap(hPS, (PBITMAPINFOHEADER2)pbmi, CBM_INIT, abm[iBitmap].pbImage, (PBITMAPINFO2)pbmi);
  481.  
  482.        WinReleasePS(hPS);
  483.        free(pbmi);
  484.        }
  485.    CreateMask(abm[iBitmap].cx, abm[iBitmap].cy);
  486.    GpiDeleteBitmap(hbmXOR);
  487.    }
  488. }
  489. #pragma    subtitle("   View Images - View Pointer Dialogue Procedure")
  490. #pragma    page( )
  491.  
  492. /* --- ViewDlgProc ------------------------------------- [ Public ] ---    */
  493. /*                                    */
  494. /*     This function is    used to    process    the messages for the dialog    */
  495. /*     procedure.                            */
  496. /*                                    */
  497. /*     Upon Entry:                            */
  498. /*                                    */
  499. /*     HWND   hWnd; = Dialog Window Handle                */
  500. /*     ULONG  msg;  = PM Message                    */
  501. /*     MPARAM mp1;  = Message Parameter    1                */
  502. /*     MPARAM mp2;  = Message Parameter    2                */
  503. /*                                    */
  504. /*     Upon Exit:                            */
  505. /*                                    */
  506. /*     ViewDlgProc = Message Handling Result                */
  507. /*                                    */
  508. /* --------------------------------------------------------------------    */
  509.  
  510. MRESULT    EXPENTRY ViewDlgProc(HWND hWnd,    ULONG msg, MPARAM mp1, MPARAM mp2)
  511.  
  512. {
  513. HPS    hPS;               /* Presentation Space Handle        */
  514. MRESULT    mr;               /* Message Return            */
  515. RECTL    rcl;               /* Window Rectangle            */
  516. POINTL    aptl[4];           /* Display Points            */
  517.  
  518. switch ( msg )
  519.    {
  520. /************************************************************************/
  521. /* Perform dialog initialization                    */
  522. /************************************************************************/
  523.  
  524.    case    WM_INITDLG :
  525.        fTest = FALSE;
  526.        BuildMaskImage( );
  527.        WinQueryWindowRect(hWnd,    &rcl);
  528.        ptlMask.x = (rcl.xRight - rcl.xLeft) / 2L - abm[iBitmap].cx - 5L;
  529.        ptlMask.y = ptlImage.y =    (rcl.yTop - rcl.yBottom) / 2L -    (abm[iBitmap].cy * 2L +    10L) / 2L;
  530.  
  531.        ptlImage.x = (rcl.xRight    - rcl.xLeft) / 2L + 5L;
  532.        break;
  533.  
  534.    case    WM_MOUSEMOVE :
  535.  
  536. /************************************************************************/
  537. /* Mouse pointer being moved                        */
  538. /************************************************************************/
  539.  
  540.        if ( fTest )
  541.        {
  542.                /* Get the current pointer position        */
  543.  
  544.        aptlImage[0].x = SHORT1FROMMP(mp1);
  545.        aptlImage[0].y = SHORT2FROMMP(mp1);
  546.  
  547.                /* Check    to see if the pointer position is    */
  548.                /* different from the location where the    image    */
  549.                /* was last drawn.  Also    check to make sure that    */
  550.                /* the position is only updated every forth    */
  551.                /* pixel.  This results in a smoother motion    */
  552.                /* since    the drawing routines are not at    a    */
  553.                /* device level.                    */
  554.  
  555.        if (    memcmp(&ptlMouse, aptlImage, sizeof(POINTL)) &&    (!(aptlImage[0].x % 4) || !(aptlImage[0].y % 4)) )
  556.            {
  557.                /* New position,    restore    the background        */
  558.  
  559.            RestoreBackground( );
  560.  
  561.                /* Save the background of the new location    */
  562.  
  563.            ptlBackground = aptlImage[0];
  564.            SaveBackground(hWnd);
  565.  
  566.                /* Calculate the    new position based on desktop    */
  567.                /* location                    */
  568.  
  569.            ptlMouse    = aptlImage[0];
  570.            WinMapWindowPoints(hWnd,    HWND_DESKTOP, aptlImage, 1L);
  571.  
  572.                /* Initialize the display points    for the    image    */
  573.                /* and draw it                    */
  574.  
  575.            aptlImage[2].y =    0L;
  576.            aptlImage[1].x =    aptlImage[0].x + aptlImage[3].x;
  577.            aptlImage[1].y =    aptlImage[0].y + (aptlImage[3].y = abm[iBitmap].cy);
  578.  
  579.            GpiSetBackColor(hpsDesktop, CLR_WHITE);
  580.            GpiWCBitBlt(hpsDesktop, hbmMask,     4L, aptlImage,    ROP_SRCAND, BBO_OR);
  581.            GpiWCBitBlt(hpsDesktop, hbmImage, 4L, aptlImage,    ROP_SRCPAINT, BBO_OR);
  582.            GpiSetBackColor(hpsDesktop, CLR_BLACK);
  583.            aptlImage[3].y =    ((aptlImage[2].y = abm[iBitmap].cy) << 1) + 1;
  584.            GpiWCBitBlt(hpsDesktop, hbmMask,     4L, aptlImage,    ROP_SRCINVERT, BBO_OR);
  585.            }
  586.        }
  587.        else
  588.        return(WinDefDlgProc(hWnd, msg, mp1,    mp2));
  589.        break;
  590.  
  591.    case    WM_BUTTON1DOWN :
  592.    case    WM_BUTTON2DOWN :
  593.    case    WM_BUTTON3DOWN :
  594.  
  595. /************************************************************************/
  596. /* Button 1 being depressed                        */
  597. /************************************************************************/
  598.  
  599.        if ( fTest )
  600.        {
  601.        fTest = FALSE;
  602.        DestroyBackgroundBitmap( );
  603.        }
  604.        break;
  605.  
  606. /************************************************************************/
  607. /* Process push    button selections                    */
  608. /************************************************************************/
  609.  
  610.    case    WM_COMMAND :
  611.        switch (    SHORT1FROMMP(mp1) )
  612.        {
  613.        case    DID_TEST :
  614.            if ( fTest )
  615.            {
  616.            fTest = FALSE;
  617.            DestroyBackgroundBitmap( );
  618.            }
  619.            else
  620.            {
  621.            fTest = TRUE;
  622.            CreateBackgroundBitmap( );
  623.            aptlImage[2].x = 0L;
  624.            aptlImage[3].x = abm[iBitmap].cx;
  625.  
  626.            WinQueryPointerPos(HWND_DESKTOP, &ptlMouse);
  627.            ptlBackground = ptlMouse;
  628.            SaveBackground(hWnd);
  629.            }
  630.            break;
  631.  
  632.        case    DID_OK :
  633.            if ( fTest )
  634.            {
  635.            fTest = FALSE;
  636.            DestroyBackgroundBitmap( );
  637.            }
  638.            GpiDeleteBitmap(hbmImage);
  639.            GpiDeleteBitmap(hbmMask);
  640.            WinDismissDlg(hWnd, TRUE);
  641.            break;
  642.        }
  643.        break;
  644.  
  645.    case    WM_PAINT :
  646.        mr = WinDefDlgProc(hWnd,    msg, mp1, mp2);
  647.  
  648.        aptl[2].x = aptl[2].y = 0L;
  649.        aptl[1].x = (aptl[0].x =    ptlMask.x) + (aptl[3].x    = abm[iBitmap].cx);
  650.        aptl[1].y = (aptl[0].y =    ptlMask.y) + (aptl[3].y    = abm[iBitmap].cy << 1UL);
  651.  
  652.        GpiSetBackColor(hPS = WinGetPS(hWnd), CLR_WHITE);
  653.        GpiWCBitBlt(hPS,    hbmMask, 4L, aptl, ROP_SRCCOPY,    BBO_IGNORE);
  654.  
  655.        aptl[1].x = (aptl[0].x =    ptlImage.x) + abm[iBitmap].cx;
  656.        aptl[1].y = aptl[0].y + (aptl[3].y = abm[iBitmap].cy);
  657.  
  658.        GpiWCBitBlt(hPS,    hbmMask,  4L, aptl, ROP_SRCAND,    BBO_IGNORE);
  659.        GpiWCBitBlt(hPS,    hbmImage, 4L, aptl, ROP_SRCPAINT, BBO_IGNORE);
  660.        GpiSetBackColor(hPS, CLR_BLACK);
  661.        aptl[2].y = abm[iBitmap].cy + 1;
  662.        aptl[3].y = (abm[iBitmap].cy << 1) + 1;
  663.        GpiWCBitBlt(hPS,    hbmMask,  4L, aptl, ROP_SRCINVERT, BBO_IGNORE);
  664.  
  665.        WinReleasePS(hPS);
  666.        return(mr);
  667.  
  668. /************************************************************************/
  669. /* Close requested, exit dialogue                    */
  670. /************************************************************************/
  671.  
  672.    case    WM_CLOSE :
  673.        if ( fTest )
  674.        {
  675.        fTest = FALSE;
  676.        DestroyBackgroundBitmap( );
  677.        }
  678.        GpiDeleteBitmap(hbmMask);
  679.        GpiDeleteBitmap(hbmImage);
  680.        WinDismissDlg(hWnd, FALSE);
  681.        break;
  682.             /* Pass    through    unhandled messages        */
  683.    default :
  684.        return(WinDefDlgProc(hWnd, msg, mp1, mp2));
  685.    }
  686. return(0L);
  687. }
  688.