home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PJ8_3.ZIP / HITTEST.C < prev    next >
Text File  |  1990-01-22  |  6KB  |  191 lines

  1. #define INCL_WIN
  2. #define INCL_GPI
  3. #include <os2.h>
  4.  
  5.  
  6. // typedefs
  7.  
  8. typedef  struct wdw_params {
  9.     MRESULT response;
  10.     LONG    pattern,
  11.             pattern1,
  12.             pattern2;
  13. } WDW_PARAMS;
  14. typedef WDW_PARAMS  *NPWDW_PARAMS;
  15. typedef WDW_PARAMS FAR  *PWDW_PARAMS;
  16.  
  17.  
  18. // global variables
  19.  
  20. HAB     vhab;                                       // anchor block handle
  21. HHEAP   vhHeap;                                     // heap handle
  22.  
  23. WDW_PARAMS    vdata[] = {
  24.     MRFROMSHORT(HT_DISCARD),     PATSYM_SOLID, PATSYM_SOLID, PATSYM_NOSHADE,
  25.     MRFROMSHORT(HT_TRANSPARENT), PATSYM_DIAG1, PATSYM_DIAG1, PATSYM_DIAG3,
  26.     MRFROMSHORT(HT_NORMAL),      PATSYM_VERT,  PATSYM_VERT,  PATSYM_HORIZ
  27. };
  28.  
  29.  
  30. // function declarations
  31.  
  32. MRESULT EXPENTRY    ClientWndProc(HWND, USHORT, MPARAM, MPARAM);
  33. MRESULT EXPENTRY    HittestWndProc(HWND, USHORT, MPARAM, MPARAM);
  34. VOID    main(VOID);
  35.  
  36.  
  37. VOID main(VOID)
  38. {
  39.  
  40.     static ULONG    FrameFlags;                     // frame flags
  41.     HMQ     hmq;                                    // msg queue handle
  42.     HWND    hwndFrame,                              // frame window handle
  43.             hwndClient;                             // client window handle
  44.     QMSG    qmsg;                                   // window message queue
  45.  
  46.     vhab = WinInitialize(0);
  47.     hmq = WinCreateMsgQueue(vhab, 0);
  48.     vhHeap = WinCreateHeap(0, 0, 0, 0, 0, 0);
  49.  
  50.     WinRegisterClass(vhab, "Hittest", ClientWndProc, CS_SIZEREDRAW, 0);
  51.  
  52.     FrameFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_MINMAX |
  53.                  FCF_SHELLPOSITION | FCF_TASKLIST;
  54.  
  55.     hwndFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE, &FrameFlags,
  56.                                    "Hittest", NULL, WS_CLIPCHILDREN, NULL,
  57.                                    NULL, &hwndClient);
  58.  
  59.     while (WinGetMsg(vhab, &qmsg, NULL, 0, 0))
  60.          WinDispatchMsg(vhab, &qmsg);
  61.  
  62.     WinDestroyHeap(vhHeap);
  63.     WinDestroyWindow(hwndFrame);
  64.     WinDestroyMsgQueue(hmq);
  65.     WinTerminate(vhab);
  66.  
  67. }
  68.  
  69.  
  70. MRESULT EXPENTRY ClientWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  71. {
  72.  
  73.     static LONG color;                              // background color
  74.     HPS     hps;                                    // PS handle
  75.     RECTL   rcl;                                    // window coordinates
  76.     SHORT   i,                                      // window ID
  77.             cxClient,                               // client window width
  78.             cyClient,                               // & height
  79.             wdwWidth,                               // child window width
  80.             wdwHeight;                              // & height
  81.  
  82.     switch (msg) {
  83.     case WM_CREATE :
  84.         WinRegisterClass(vhab, "Test", HittestWndProc,
  85.                          CS_SIZEREDRAW | CS_HITTEST,
  86.                          sizeof(NPWDW_PARAMS));
  87.  
  88.         for (i = 0; i < 3; i++)
  89.             WinCreateWindow(hwnd, "Test", NULL, WS_VISIBLE,
  90.                             0, 0, 0, 0,
  91.                             hwnd, HWND_TOP, i, (PVOID)&vdata[i], NULL);
  92.  
  93.         color = CLR_BACKGROUND;                     // initial bkg color
  94.         break;
  95.  
  96.     case WM_SIZE:
  97.         cxClient = SHORT1FROMMP(mp2);               // get size of client
  98.         cyClient = SHORT2FROMMP(mp2);               // window
  99.  
  100.         wdwWidth = cxClient / 5;                    // size for child windows
  101.         wdwHeight = cyClient / 5;
  102.  
  103.         for (i = 0; i < 3; i++)
  104.             WinSetWindowPos(WinWindowFromID(hwnd, i), NULL,
  105.                             ((i + 1) * (cxClient / 4)) - (wdwWidth / 2),
  106.                             (cyClient / 2) - (wdwHeight / 2),
  107.                             wdwWidth, wdwHeight,
  108.                             SWP_MOVE | SWP_SIZE);
  109.  
  110.         break;
  111.  
  112.     case WM_PAINT:
  113.         hps = WinBeginPaint(hwnd, NULL, NULL);
  114.         WinQueryWindowRect(hwnd, &rcl);
  115.         WinFillRect(hps, &rcl, color);
  116.         WinEndPaint(hps);
  117.         break;
  118.  
  119.     case WM_BUTTON1DOWN:
  120.         color = (color == CLR_BACKGROUND) ? CLR_PINK : CLR_BACKGROUND;
  121.         WinInvalidateRect(hwnd, NULL, FALSE);
  122.         break;
  123.  
  124.     default:
  125.         return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  126.     }
  127.  
  128.     return(NULL);
  129.  
  130. }
  131.  
  132.  
  133. MRESULT EXPENTRY HittestWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  134. {
  135.  
  136.     HPS     hps;                                    // PS handle
  137.     NPWDW_PARAMS WinData;                           // window specific data
  138.     POINTL  ptl;                                    // point coordinates
  139.     RECTL   rcl;                                    // rectangle coordinates
  140.  
  141.     WinData = (NPWDW_PARAMS)WinQueryWindowUShort(hwnd, 0);
  142.  
  143.     switch (msg) {
  144.     case WM_CREATE:
  145.         WinData = (NPWDW_PARAMS)WinAllocMem(vhHeap, sizeof(WDW_PARAMS));
  146.  
  147.         WinData->pattern = ((PWDW_PARAMS)mp1)->pattern1;
  148.         WinData->pattern1 = ((PWDW_PARAMS)mp1)->pattern1;
  149.         WinData->pattern2 = ((PWDW_PARAMS)mp1)->pattern2;
  150.         WinData->response = ((PWDW_PARAMS)mp1)->response;
  151.  
  152.         WinSetWindowUShort(hwnd, 0, (USHORT)WinData);
  153.         break;
  154.  
  155.     case WM_PAINT:
  156.         hps = WinBeginPaint(hwnd, NULL, NULL);
  157.         WinQueryWindowRect(hwnd, &rcl);
  158.  
  159.         GpiErase(hps);
  160.         GpiSetPattern(hps, WinData->pattern);
  161.         ptl.x = 0;                                      // lower left corner
  162.         ptl.y = 0;                                      // of window
  163.         GpiMove(hps, &ptl);
  164.         ptl.x = --rcl.xRight;                           // decrement so we can
  165.         ptl.y = --rcl.yTop;                             // see the border
  166.         GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0L, 0L);     // draw box w/border
  167.  
  168.         WinEndPaint(hps);
  169.         break;
  170.  
  171.     case WM_BUTTON1DOWN:
  172.         WinData->pattern = (WinData->pattern == WinData->pattern1) ?
  173.                                    WinData->pattern2 : WinData->pattern1;
  174.         WinInvalidateRect(hwnd, NULL, FALSE);
  175.         break;
  176.  
  177.     case WM_HITTEST:
  178.         return(WinData->response);
  179.  
  180.     case WM_DESTROY:
  181.         WinFreeMem(vhHeap, (NPBYTE)WinData, sizeof(WDW_PARAMS));
  182.         break;
  183.  
  184.     default:
  185.         return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  186.     }
  187.  
  188.     return(NULL);
  189.  
  190. }
  191.