Annotation of pmsdk/samples/petzold/chap06/checker3.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.