home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bmp4.zip / VIEWWND.C < prev    next >
Text File  |  1996-01-29  |  14KB  |  395 lines

  1. #pragma    title("Pointer Creation Tool  --  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 "makeptr.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-11-06                        */
  23. /*  Revised:   1995-11-06                        */
  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. /* #define WIDTHBYTES(cx)  ((((ULONG)(cx)+31UL)    >> 5UL)    << 2UL)  */
  60. #define    WIDTHBYTES(cx, cBits)  (((cx * cBits + 31L) & 0xffffffe0) >> 3)
  61.  
  62. HBITMAP    hbmROP = 0;           /* Bitmap Handle            */
  63. LONG    lScale = 100L;           /* Scale Factor            */
  64. RECTL    rclDest;           /* Destination Rectangle        */
  65. RECTL    rclImage;           /* Image Rectangle            */
  66. POINTL    aptlArea[8];           /* Shadow Points            */
  67. RECTL    rclROP;               /* ROP Image    Rectangle        */
  68. LONG    cxROP;               /* ROP Image    Width            */
  69. LONG    cyROP;               /* ROP Image    Height            */
  70. LONG    cxImage;           /* Bitmap Image Width        */
  71. LONG    cyImage;           /* Bitmap Image Height        */
  72. LONG    lHorzRange;           /* Horizontal Scroll    Bar Range    */
  73. LONG    lVertRange;           /* Vertical Scroll Bar Range        */
  74. LONG    lHorzPos;           /* Horizontal Scroll    Bar Position    */
  75. LONG    lVertPos;           /* Vertical Scroll Bar Position    */
  76. LONG    cxWindow;           /* Window Width            */
  77. LONG    cyWindow;           /* Window Height            */
  78.  
  79. LONG    iImage;               /* Bitmap Image Index        */
  80.  
  81. BOOL    fBitmapArray = TRUE;       /* Bitmap Array Display Flag        */
  82.  
  83. static VOID SizeBitmapStack(HWND hWnd);
  84.  
  85. #pragma    subtitle("   Module Purpose - Bitmap Stack Sizing Function")
  86. #pragma    page( )
  87.  
  88. /* --- SizeBitmapStack --------------------------------    [ Private ] ---    */
  89. /*                                    */
  90. /*     This function is    used to    calculate the size and position    of    */
  91. /*     the bitmaps from    the bitmap array for the window.        */
  92. /*                                    */
  93. /*     Upon Entry:                            */
  94. /*                                    */
  95. /*     HWND hWnd; = Window Handle                    */
  96. /*                                    */
  97. /*     Upon Exit:                            */
  98. /*                                    */
  99. /*     Nothing                                */
  100. /*                                    */
  101. /* --------------------------------------------------------------------    */
  102.  
  103. static VOID SizeBitmapStack(HWND hWnd)
  104.  
  105. {
  106. BITMAPINFOHEADER bmp;           /* Bitmap Information Header        */
  107. RECTL         rcl;           /* Window Rectangle            */
  108. LONG         cx;           /* Bitmap Width            */
  109. LONG         cy;           /* Bitmap Height            */
  110. LONG         xImage;       /* Image Starting Point        */
  111. register INT i;               /* Loop Counter            */
  112.  
  113.  
  114. WinQueryWindowRect(hWnd, &rcl);
  115.     
  116. for ( i    = 0, cx    = 10 * (cBitmaps - 1), cy = 0L;    i < cBitmaps; i++ )
  117.    {
  118.    GpiQueryBitmapParameters(abm[i].hbm,    &bmp);
  119.  
  120.    cx += bmp.cx;
  121.    if (    bmp.cy > cy )
  122.        cy = bmp.cy;
  123.    }
  124.  
  125. rclImage.xRight    = (rclImage.xLeft   = ((rcl.xRight - rcl.xLeft)    / 2L) -    (cx / 2L)) + cx;
  126. rclImage.yTop    = (rclImage.yBottom = ((rcl.yTop - rcl.yBottom)    / 2L) -    (cy / 2L)) + cy;
  127.  
  128. xImage = rclImage.xLeft;
  129.  
  130. rclImage.xLeft     -= 3L;
  131. rclImage.yBottom -= 3L;
  132. rclImage.xRight     += 3L;
  133. rclImage.yTop     += 3L;
  134.  
  135. for ( i    = 0; i < cBitmaps; i++ )
  136.    {
  137.    GpiQueryBitmapParameters(abm[i].hbm,    &bmp);
  138.  
  139.    abm[i].rclDest.xRight = (abm[i].rclDest.xLeft   = xImage) + bmp.cx;
  140.    abm[i].rclDest.yTop     = (abm[i].rclDest.yBottom = ((rcl.yTop    - rcl.yBottom) / 2L) - (bmp.cy / 2L)) +    bmp.cy;
  141.  
  142.                /* Form the final boundary points        */
  143.  
  144.    abm[i].aptlArea[0].x    = abm[i].rclDest.xLeft    - 2L;
  145.    abm[i].aptlArea[0].y    = abm[i].rclDest.yTop    + 2L;
  146.    abm[i].aptlArea[1].x    = abm[i].rclDest.xRight    + 2L;
  147.    abm[i].aptlArea[1].y    = abm[i].rclDest.yTop    + 2L;
  148.  
  149.    abm[i].aptlArea[2].x    = abm[i].rclDest.xRight     + 2L;
  150.    abm[i].aptlArea[2].y    = abm[i].rclDest.yBottom - 2L;
  151.    abm[i].aptlArea[3].x    = abm[i].rclDest.xLeft     - 2L;
  152.    abm[i].aptlArea[3].y    = abm[i].rclDest.yBottom - 2L;
  153.  
  154.    abm[i].aptlArea[4].x    = abm[i].rclDest.xLeft    - 1L;
  155.    abm[i].aptlArea[4].y    = abm[i].rclDest.yTop    + 1L;
  156.    abm[i].aptlArea[5].x    = abm[i].rclDest.xRight    + 1L;
  157.    abm[i].aptlArea[5].y    = abm[i].rclDest.yTop    + 1L;
  158.  
  159.    abm[i].aptlArea[6].x    = abm[i].rclDest.xRight     + 1L;
  160.    abm[i].aptlArea[6].y    = abm[i].rclDest.yBottom - 1L;
  161.    abm[i].aptlArea[7].x    = abm[i].rclDest.xLeft     - 1L;
  162.    abm[i].aptlArea[7].y    = abm[i].rclDest.yBottom - 1L;
  163.  
  164.    xImage += (bmp.cx + 10L);
  165.    }
  166. }
  167. #pragma    subtitle("   Client Window - Client Window Procedure")
  168. #pragma    page( )
  169.  
  170. /* --- ROPsTestWndProc --------------------------------- [ Public ] ---    */
  171. /*                                    */
  172. /*     This function is    used to    process    the messages sent to the    */
  173. /*     applications client window.                    */
  174. /*                                    */
  175. /*     Upon Entry:                            */
  176. /*                                    */
  177. /*     HWND   hWnd; = Window Handle                    */
  178. /*     ULONG  msg;  = PM Message                    */
  179. /*     MPARAM mp1;  = Message Parameter    1                */
  180. /*     MPARAM mp2;  = Message Parameter    2                */
  181. /*                                    */
  182. /*     Upon Exit:                            */
  183. /*                                    */
  184. /*     ROPsTestWndProc = Message Handling Result            */
  185. /*                                    */
  186. /* --------------------------------------------------------------------    */
  187.  
  188. MRESULT    EXPENTRY ViewWndProc(HWND hWnd,    ULONG msg, MPARAM mp1, MPARAM mp2)
  189.  
  190. {
  191. CHAR   szTitle[300];           /* Title Bar    Text            */
  192. HPS    hPS;               /* Presentation Space Handle        */
  193. RECTL  rcl;               /* Window Rectangle            */
  194. POINTL ptl;               /* Display Point            */
  195. PBYTE  pbImage;               /* Image Pointer            */
  196. ULONG  x;               /* x    Position            */
  197. ULONG  y;               /* y    Position            */
  198. register INT i;               /* Index                */
  199.  
  200. switch ( msg )
  201.    {
  202. /************************************************************************/
  203. /* Window being    created, perform window    initialization            */
  204. /************************************************************************/
  205.  
  206.    case    WM_CREATE :
  207.  
  208.        hptrWait     = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT,    FALSE);
  209.        hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW,    FALSE);
  210.  
  211.        cxScreen    = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  212.  
  213.        hmenuMakePtr = WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), FID_MENU);
  214.  
  215.                /************************************************/
  216.                /* PDSGetTemplate is used to allow controls in  */
  217.                /* windows.  Do not remove this function    if you */
  218.                /* intend to include controls within the    window.*/
  219.                /************************************************/
  220.  
  221.        PDSGetTemplate(hWnd, WIN_VIEWER);
  222.        break;
  223.  
  224. /************************************************************************/
  225. /* Window being    sized                            */
  226. /************************************************************************/
  227.  
  228.    case    WM_SIZE    :
  229.        SizeBitmapStack(hWnd);
  230.        break;
  231.  
  232. /************************************************************************/
  233. /* Perform menu    initialization                        */
  234. /************************************************************************/
  235.  
  236.    case    WM_INITMENU :
  237.        switch (    SHORT1FROMMP(mp1) )
  238.        {
  239.        case    IDM_FILE :
  240.            break;
  241.  
  242.        }
  243.        break;
  244.  
  245. /************************************************************************/
  246. /* Process key press from keyboard                    */
  247. /************************************************************************/
  248.  
  249.    case    WM_CHAR    :
  250.                /************************************************/
  251.                /* PDSKeyProc is    used to    allow controls in      */
  252.                /* windows.  Do not remove this function    if you */
  253.                /* intend to include controls within the    window.*/
  254.                /************************************************/
  255.  
  256.        return(PDSKeyProc(hWnd, msg, mp1, mp2));
  257.  
  258. /************************************************************************/
  259. /* Process control selections                        */
  260. /************************************************************************/
  261.  
  262.    case    WM_COMMAND :
  263.        switch (    SHORT1FROMMP(mp1) )
  264.        {
  265.        case    IDM_OPEN :
  266.            if ( WinDlgBox(HWND_DESKTOP, hwndMakePtrFrame, (PFNWP)OpenDlgProc, (HMODULE)NULL, DLG_OPEN, NULL) )
  267.            {
  268.            WinSetPointer(HWND_DESKTOP, hptrWait);
  269.            GetBitmap(szBitmapFile);
  270.            SizeBitmapStack(hWnd);
  271.            WinInvalidateRect(hWnd, NULL, FALSE);
  272.            strcat(memcpy(szTitle, "Make Pointer Tool - ", 23), szBitmapFile);
  273.            if (    fWindowsBitmap )
  274.                strcat(szTitle, " [Windows 3.x format]");
  275.            else
  276.                if ( f20Bitmap )
  277.                strcat(szTitle, " [OS/2 2.x format]");
  278.                else
  279.                strcat(szTitle, " [OS/2 1.x format]");
  280.            WinSetWindowText(hwndMakePtrFrame, szTitle);
  281.            WinSetPointer(HWND_DESKTOP, hptrArrow);
  282.            }
  283.            break;
  284.        }
  285.        break;
  286.  
  287.    case    WM_BUTTON2DOWN :
  288.  
  289. /************************************************************************/
  290. /* Button 2 being depressed                        */
  291. /************************************************************************/
  292.  
  293.        ptl.x = (LONG)(SHORT)SHORT1FROMMP(mp1);
  294.        ptl.y = (LONG)(SHORT)SHORT2FROMMP(mp1);
  295.        for ( i = 0; i <    cBitmaps; i++ )
  296.        if (    WinPtInRect(hAB, &abm[i].rclDest, &ptl)    )
  297.            {
  298.            pbImage = abm[iBitmap = i].pbImage + (WIDTHBYTES(abm[i].cx, abm[i].cBitCount) * (y = ptl.y - abm[i].rclDest.yBottom));
  299.            x = ptl.x - abm[i].rclDest.xLeft;
  300.  
  301.            switch (    abm[i].cColours    )
  302.            {
  303.            case    2 :
  304.                pbImage += (x >>    3UL);
  305.                iClr = !!(*pbImage & (BYTE)(0x80    >> (x &    0x07)));
  306.                break;
  307.  
  308.            case    16 :
  309.                pbImage += (x >>    1UL);
  310.                if ( x &    1 )
  311.                iClr    = (*pbImage & 0x0F);
  312.                else
  313.                iClr    = ((ULONG)(*pbImage & 0xF0) >> 4);
  314.                break;
  315.  
  316.            case    256 :
  317.                pbImage += x;
  318.                iClr = *pbImage;
  319.                break;
  320.  
  321.            default :
  322.            /* ReturnColor = GetColor((PRGB)pbImage, (ULONG)x);  */
  323.                /* return ReturnColor;  */
  324.                break;
  325.            }
  326.            WinDlgBox(HWND_DESKTOP, hwndMakePtrFrame, (PFNWP)ViewDlgProc, (HMODULE)NULL, DLG_VIEW, NULL);
  327.  
  328.            break;
  329.            }
  330.        break;
  331.  
  332. /************************************************************************/
  333. /* Erase window    background                        */
  334. /************************************************************************/
  335.  
  336.    case    WM_ERASEBACKGROUND :
  337.        WinQueryWindowRect(hWnd,    &rcl);
  338.        WinFillRect((HPS)LONGFROMMP(mp1), &rcl, CLR_PALEGRAY);
  339.        break;
  340.  
  341. /************************************************************************/
  342. /* Paint client    window                            */
  343. /************************************************************************/
  344.  
  345.    case    WM_PAINT :
  346.        GpiCreateLogColorTable(hPS = WinBeginPaint(hWnd,    (HPS)NULL, &rcl), 0UL, LCOLF_RGB, 0L, 0L, (PLONG)NULL);
  347.  
  348.                /* Display the bitmap array images side-by-side    */
  349.  
  350.        WinFillRect(hPS,    &rcl, RGBCLR_PALEGRAY);
  351.        for ( i = 0; i <    cBitmaps; i++ )
  352.        {
  353.                /* Draw the bitmap from the array        */
  354.  
  355.        WinDrawBitmap(hPS, abm[i].hbm, (PRECTL)NULL,    (PPOINTL)(PVOID)&abm[i].rclDest, RGB_WHITE, RGB_BLACK, DBM_NORMAL);
  356.  
  357.                /* Draw the 3-D frame around the    image        */
  358.  
  359.        GpiSetColor(hPS, RGBCLR_SHADOW);
  360.        GpiMove(hPS,    &abm[i].aptlArea[7]);
  361.        GpiPolyLine(hPS, 2L,    &abm[i].aptlArea[4]);
  362.  
  363.        GpiSetColor(hPS, RGB_WHITE);
  364.        GpiPolyLine(hPS, 2L,    &abm[i].aptlArea[6]);
  365.  
  366.        GpiSetColor(hPS, RGB_BLACK);
  367.        GpiMove(hPS,    &abm[i].aptlArea[3]);
  368.        GpiPolyLine(hPS, 2L,    &abm[i].aptlArea[0]);
  369.  
  370.        GpiSetColor(hPS, RGBCLR_PALEGRAY);
  371.        GpiPolyLine(hPS, 2L,    &abm[i].aptlArea[2]);
  372.        }
  373.        WinEndPaint(hPS);
  374.        break;
  375.  
  376. /************************************************************************/
  377. /* Window being    destroyed, perform clean-up operations            */
  378. /************************************************************************/
  379.  
  380.    case    WM_DESTROY :
  381.  
  382.        for ( i = 0; i <    cBitmaps; i++ )
  383.        GpiDeleteBitmap(abm[i].hbm);
  384.  
  385.        if ( pb )
  386.        free(pb);
  387.        break;
  388.  
  389.                /* Default message processing            */
  390.    default :
  391.        return(WinDefWindowProc(hWnd, msg, mp1, mp2));
  392.    }
  393. return(0L);
  394. }
  395.