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

1.1       root        1: /*-------------------------------------------
                      2:    CHECKER1.C -- Mouse Hit-Test Demo Program 
                      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: 
                     15: int main (void)
                     16:      {
                     17:      static CHAR szClientClass [] = "Checker1" ;
                     18:      HAB         hab ;
                     19:      HMQ         hmq ;
                     20:      HWND        hwndFrame, hwndClient ;
                     21:      QMSG        qmsg ;
                     22:      ULONG       flFrameFlags = FCF_STANDARD & ~FCF_MENU ;
                     23:      ULONG       flFrameStyle = WS_VISIBLE ;
                     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, flFrameStyle,
                     31:                                      &flFrameFlags, szClientClass,
                     32:                                      "Mouse Hit-Test Program No. 1",
                     33:                                      0L, NULL, 0, &hwndClient) ;
                     34: 
                     35:      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
                     36:           WinDispatchMsg (hab, &qmsg) ;
                     37: 
                     38:      WinDestroyWindow (hwndFrame) ;
                     39:      WinDestroyMsgQueue (hmq) ;
                     40:      WinTerminate (hab) ;
                     41:      
                     42:      return 0 ;
                     43:      }
                     44: 
                     45: VOID DrawLine (HPS hps, LONG x1, LONG y1, LONG x2, LONG y2)
                     46:      {
                     47:      POINTL ptl ;
                     48: 
                     49:      ptl.x = x1 ;  ptl.y = y1 ;  GpiMove (hps, &ptl) ;
                     50:      ptl.x = x2 ;  ptl.y = y2 ;  GpiLine (hps, &ptl) ;
                     51:      }
                     52: 
                     53: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
                     54:      {
                     55:      static BOOL  bBlockState [DIVISIONS] [DIVISIONS] ;
                     56:      static SHORT xBlock, yBlock ;
                     57:      HPS          hps ;
                     58:      RECTL        rcl ;
                     59:      SHORT        x, y ;
                     60: 
                     61:      switch (msg)
                     62:           {
                     63:           case WM_SIZE:
                     64:                xBlock = SHORT1FROMMP (mp2) / DIVISIONS ;
                     65:                yBlock = SHORT2FROMMP (mp2) / DIVISIONS ;
                     66:                return 0 ;
                     67: 
                     68:           case WM_BUTTON1DOWN:
                     69:           case WM_BUTTON1DBLCLK:
                     70:                if (xBlock > 0 && yBlock > 0)
                     71:                     {
                     72:                     x = SHORT1FROMMP (mp1) / xBlock ;
                     73:                     y = SHORT2FROMMP (mp1) / yBlock ;
                     74: 
                     75:                     if (x < DIVISIONS && y < DIVISIONS)
                     76:                          {
                     77:                          bBlockState [x][y] = !bBlockState [x][y] ;
                     78: 
                     79:                          rcl.xRight = xBlock + (rcl.xLeft   = x * xBlock) ;
                     80:                          rcl.yTop   = yBlock + (rcl.yBottom = y * yBlock) ;
                     81: 
                     82:                          WinInvalidateRect (hwnd, &rcl, FALSE) ;
                     83:                          }
                     84:                     else
                     85:                          WinAlarm (HWND_DESKTOP, WA_WARNING) ;
                     86:                     }
                     87:                else
                     88:                     WinAlarm (HWND_DESKTOP, WA_WARNING) ;
                     89: 
                     90:                return 1 ;
                     91: 
                     92:           case WM_PAINT:
                     93:                hps = WinBeginPaint (hwnd, NULL, NULL) ;
                     94: 
                     95:                GpiErase (hps) ;
                     96: 
                     97:                if (xBlock > 0 && yBlock > 0)
                     98:                     for (x = 0 ; x < DIVISIONS ; x++)
                     99:                          for (y = 0 ; y < DIVISIONS ; y++)
                    100:                               {
                    101:                               rcl.xRight = xBlock + (rcl.xLeft   = x * xBlock);
                    102:                               rcl.yTop   = yBlock + (rcl.yBottom = y * yBlock);
                    103: 
                    104:                               WinDrawBorder (hps, &rcl, 1, 1,
                    105:                                              CLR_NEUTRAL, CLR_BACKGROUND,
                    106:                                              DB_STANDARD | DB_INTERIOR) ;
                    107: 
                    108:                               if (bBlockState [x][y])
                    109:                                    {
                    110:                                    DrawLine (hps, rcl.xLeft,  rcl.yBottom,
                    111:                                                   rcl.xRight, rcl.yTop) ;
                    112: 
                    113:                                    DrawLine (hps, rcl.xLeft,  rcl.yTop,
                    114:                                                   rcl.xRight, rcl.yBottom) ;
                    115:                                    }
                    116:                               }
                    117:                WinEndPaint (hps) ;
                    118:                return 0 ;
                    119:           }
                    120:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
                    121:      }

unix.superglobalmegacorp.com

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