home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk11 / petzold / chap09 / checker3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-20  |  5.0 KB  |  141 lines

  1. /*--------------------------------------------------------------
  2.    CHECKER3.C -- Mouse Hit-Test Demo Program with Child Windows
  3.   --------------------------------------------------------------*/
  4.  
  5. #define INCL_WIN
  6. #include <os2.h>
  7.  
  8. #define DIVISIONS 5
  9.  
  10. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  11. MRESULT EXPENTRY ChildWndProc  (HWND, USHORT, MPARAM, MPARAM) ;
  12.  
  13. HAB  hab ;
  14.  
  15. int main (void)
  16.      {
  17.      static CHAR  szClientClass [] = "Checker3" ;
  18.      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
  19.                                  FCF_SIZEBORDER    | FCF_MINMAX  |
  20.                                  FCF_SHELLPOSITION | FCF_TASKLIST ;
  21.      HMQ          hmq ;
  22.      HWND         hwndFrame, hwndClient ;
  23.      QMSG         qmsg ;
  24.  
  25.      hab = WinInitialize (0) ;
  26.      hmq = WinCreateMsgQueue (hab, 0) ;
  27.  
  28.      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
  29.  
  30.      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
  31.                                      &flFrameFlags, szClientClass, NULL,
  32.                                      0L, NULL, 0, &hwndClient) ;
  33.  
  34.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  35.           WinDispatchMsg (hab, &qmsg) ;
  36.  
  37.      WinDestroyWindow (hwndFrame) ;
  38.      WinDestroyMsgQueue (hmq) ;
  39.      WinTerminate (hab) ;
  40.      return 0 ;
  41.      }
  42.  
  43. VOID DrawLine (HPS hps, LONG x1, LONG y1, LONG x2, LONG y2)
  44.      {
  45.      POINTL ptl ;
  46.  
  47.      ptl.x = x1 ;  ptl.y = y1 ;  GpiMove (hps, &ptl) ;
  48.      ptl.x = x2 ;  ptl.y = y2 ;  GpiLine (hps, &ptl) ;
  49.      }
  50.  
  51. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  52.      {
  53.      static CHAR szChildClass [] = "Checker3.Child" ;
  54.      static HWND hwndChild [DIVISIONS][DIVISIONS] ;
  55.      SHORT       xBlock, yBlock, x, y ;
  56.  
  57.      switch (msg)
  58.           {
  59.           case WM_CREATE:
  60.                WinRegisterClass (hab, szChildClass, ChildWndProc,
  61.                                  CS_SIZEREDRAW, sizeof (USHORT)) ;
  62.  
  63.                for (x = 0 ; x < DIVISIONS ; x++)
  64.                     for (y = 0 ; y < DIVISIONS ; y++)
  65.  
  66.                          hwndChild [x][y] =
  67.                               WinCreateWindow (
  68.                                         hwnd,          // Parent window
  69.                                         szChildClass,  // Window class
  70.                                         NULL,          // Window text
  71.                                         WS_VISIBLE,    // Window style
  72.                                         0, 0, 0, 0,    // Position & size
  73.                                         hwnd,          // Owner window
  74.                                         HWND_BOTTOM,   // Placement
  75.                                         y << 8 | x,    // Child window ID
  76.                                         NULL,          // Control data
  77.                                         NULL) ;        // Pres. Params
  78.                return 0 ;
  79.  
  80.           case WM_SIZE:
  81.                xBlock = SHORT1FROMMP (mp2) / DIVISIONS ;
  82.                yBlock = SHORT2FROMMP (mp2) / DIVISIONS ;
  83.  
  84.                for (x = 0 ; x < DIVISIONS ; x++)
  85.                     for (y = 0 ; y < DIVISIONS ; y++)
  86.  
  87.                          WinSetWindowPos (hwndChild [x][y], NULL,
  88.                               x * xBlock, y * yBlock, xBlock, yBlock,
  89.                               SWP_MOVE | SWP_SIZE) ;      
  90.                return 0 ;
  91.  
  92.           case WM_BUTTON1DOWN:
  93.           case WM_BUTTON1DBLCLK:
  94.                WinAlarm (HWND_DESKTOP, WA_WARNING) ;
  95.                break ;                       // do default processing
  96.  
  97.           case WM_ERASEBACKGROUND:
  98.                return 1 ;
  99.           }
  100.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  101.      }
  102.  
  103. MRESULT EXPENTRY ChildWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  104.      {
  105.      HPS   hps ;
  106.      RECTL rcl ;
  107.  
  108.      switch (msg)
  109.           {
  110.           case WM_CREATE:
  111.                WinSetWindowUShort (hwnd, 0, 0) ;
  112.                return 0 ;
  113.  
  114.           case WM_BUTTON1DOWN:
  115.           case WM_BUTTON1DBLCLK:
  116.                WinSetActiveWindow (HWND_DESKTOP, hwnd) ;
  117.                WinSetWindowUShort (hwnd, 0, !WinQueryWindowUShort (hwnd, 0)) ;
  118.                WinInvalidateRect (hwnd, NULL, FALSE) ;
  119.                return 0 ;
  120.  
  121.           case WM_PAINT:
  122.                hps = WinBeginPaint (hwnd, NULL, NULL) ;
  123.  
  124.                WinQueryWindowRect (hwnd, &rcl) ;
  125.  
  126.                WinDrawBorder (hps, &rcl, 1, 1, CLR_NEUTRAL, CLR_BACKGROUND,
  127.                                    DB_STANDARD | DB_INTERIOR) ;
  128.  
  129.                if (WinQueryWindowUShort (hwnd, 0))
  130.                     {
  131.                     DrawLine (hps, rcl.xLeft,  rcl.yBottom,
  132.                                    rcl.xRight, rcl.yTop) ;
  133.                     DrawLine (hps, rcl.xLeft,  rcl.yTop,
  134.                                    rcl.xRight, rcl.yBottom) ;
  135.                     }
  136.                WinEndPaint (hps) ;
  137.                return 0 ;
  138.           }
  139.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  140.      }
  141.