Annotation of pmsdk/samples/petzold/chap09/blokout1.c, revision 1.1.1.1

1.1       root        1: /*-----------------------------------------
                      2:    BLOKOUT1.C -- Mouse Button Demo Program 
                      3:   -----------------------------------------*/
                      4: 
                      5: #define INCL_WIN
                      6: #define INCL_GPI
                      7: #include <os2.h>
                      8: 
                      9: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
                     10: 
                     11: int main (void)
                     12:      {
                     13:      static CHAR  szClientClass [] = "BlokOut1" ;
                     14:      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
                     15:                                  FCF_SIZEBORDER    | FCF_MINMAX  |
                     16:                                  FCF_SHELLPOSITION | FCF_TASKLIST ;
                     17:      HAB          hab ;
                     18:      HMQ          hmq ;
                     19:      HWND         hwndFrame, hwndClient ;
                     20:      QMSG         qmsg ;
                     21: 
                     22:      hab = WinInitialize (0) ;
                     23:      hmq = WinCreateMsgQueue (hab, 0) ;
                     24: 
                     25:      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
                     26: 
                     27:      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
                     28:                                      &flFrameFlags, szClientClass, NULL,
                     29:                                     0L, NULL, 0, &hwndClient) ;
                     30: 
                     31:      WinSendMsg (hwndFrame, WM_SETICON,
                     32:                  WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
                     33:                  NULL) ;
                     34: 
                     35:      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
                     36:           WinDispatchMsg (hab, &qmsg) ;
                     37: 
                     38:      WinDestroyWindow (hwndFrame) ;
                     39:      WinDestroyMsgQueue (hmq) ;
                     40:      WinTerminate (hab) ;
                     41:      return 0 ;
                     42:      }
                     43: 
                     44: VOID DrawBoxOutline (HWND hwnd, POINTL *pptlStart, POINTL *pptlEnd)
                     45:      {
                     46:      HPS hps ;
                     47: 
                     48:      hps = WinGetPS (hwnd) ;
                     49:      GpiSetMix (hps, FM_INVERT) ;
                     50: 
                     51:      GpiMove (hps, pptlStart) ;
                     52:      GpiBox (hps, DRO_OUTLINE, pptlEnd, 0L, 0L) ;
                     53: 
                     54:      WinReleasePS (hps) ;
                     55:      }
                     56: 
                     57: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
                     58:      {
                     59:      static BOOL   fButtonDown, fValidBox ;
                     60:      static POINTL ptlStart, ptlEnd, ptlBoxStart, ptlBoxEnd ;
                     61:      HPS           hps ;
                     62: 
                     63:      switch (msg)
                     64:           {
                     65:           case WM_BUTTON1DOWN:
                     66:                ptlStart.x = ptlEnd.x = MOUSEMSG(&msg)->x ;
                     67:                ptlStart.y = ptlEnd.y = MOUSEMSG(&msg)->y ;
                     68: 
                     69:                DrawBoxOutline (hwnd, &ptlStart, &ptlEnd) ;
                     70: 
                     71:                fButtonDown = TRUE ;
                     72:                break ;                       // do default processing
                     73: 
                     74:           case WM_MOUSEMOVE:
                     75:                if (fButtonDown)
                     76:                     {
                     77:                     DrawBoxOutline (hwnd, &ptlStart, &ptlEnd) ;
                     78: 
                     79:                     ptlEnd.x = MOUSEMSG(&msg)->x ;
                     80:                     ptlEnd.y = MOUSEMSG(&msg)->y ;
                     81: 
                     82:                     DrawBoxOutline (hwnd, &ptlStart, &ptlEnd) ;
                     83:                     }
                     84:                break ;                       // do default processing
                     85: 
                     86:           case WM_BUTTON1UP:
                     87:                if (fButtonDown)
                     88:                     {
                     89:                     DrawBoxOutline (hwnd, &ptlStart, &ptlEnd) ;
                     90: 
                     91:                     ptlBoxStart = ptlStart ;
                     92:                     ptlBoxEnd.x = MOUSEMSG(&msg)->x ;
                     93:                     ptlBoxEnd.y = MOUSEMSG(&msg)->y ;
                     94: 
                     95:                     fButtonDown = FALSE ;
                     96:                     fValidBox = TRUE ;
                     97:                     WinInvalidateRect (hwnd, NULL, FALSE) ;
                     98:                     }
                     99:                return 0 ;
                    100: 
                    101:           case WM_PAINT:
                    102:                hps = WinBeginPaint (hwnd, NULL, NULL) ;
                    103:                GpiErase (hps) ;
                    104: 
                    105:                if (fValidBox)
                    106:                     {
                    107:                     GpiMove (hps, &ptlBoxStart) ;
                    108:                     GpiBox (hps, DRO_OUTLINEFILL, &ptlBoxEnd, 0L, 0L) ;
                    109:                     }
                    110:                if (fButtonDown)
                    111:                     {
                    112:                     GpiSetMix (hps, FM_INVERT) ;
                    113: 
                    114:                     GpiMove (hps, &ptlStart) ;
                    115:                     GpiBox (hps, DRO_OUTLINE, &ptlEnd, 0L, 0L) ;
                    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.