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

1.1       root        1: /*---------------------------------------------------
                      2:    BLOKOUT2.C -- Mouse Button & Capture 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 [] = "BlokOut2" ;
                     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   fCapture, 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:                WinSetCapture (HWND_DESKTOP, hwnd) ;
                     72:                fCapture = TRUE ;
                     73:                break ;                       // do default processing
                     74: 
                     75:           case WM_MOUSEMOVE:
                     76:                if (fCapture)
                     77:                     {
                     78:                     DrawBoxOutline (hwnd, &ptlStart, &ptlEnd) ;
                     79: 
                     80:                     ptlEnd.x = MOUSEMSG(&msg)->x ;
                     81:                     ptlEnd.y = MOUSEMSG(&msg)->y ;
                     82: 
                     83:                     DrawBoxOutline (hwnd, &ptlStart, &ptlEnd) ;
                     84:                     }
                     85:                break ;                       // do default processing
                     86: 
                     87:           case WM_BUTTON1UP:
                     88:                if (fCapture)
                     89:                     {
                     90:                     DrawBoxOutline (hwnd, &ptlStart, &ptlEnd) ;
                     91: 
                     92:                     ptlBoxStart = ptlStart ;
                     93:                     ptlBoxEnd.x = MOUSEMSG(&msg)->x ;
                     94:                     ptlBoxEnd.y = MOUSEMSG(&msg)->y ;
                     95: 
                     96:                     WinSetCapture (HWND_DESKTOP, NULL) ;
                     97:                     fCapture = FALSE ;
                     98:                     fValidBox = TRUE ;
                     99:                     WinInvalidateRect (hwnd, NULL, FALSE) ;
                    100:                     }
                    101:                return 0 ;
                    102: 
                    103:           case WM_CHAR:
                    104:                if (fCapture && CHARMSG(&msg)->fs   &  KC_VIRTUALKEY &&
                    105:                              !(CHARMSG(&msg)->fs   &  KC_KEYUP)     &&
                    106:                               CHARMSG(&msg)->vkey == VK_ESC)
                    107:                     {
                    108:                     DrawBoxOutline (hwnd, &ptlStart, &ptlEnd) ;
                    109: 
                    110:                     WinSetCapture (HWND_DESKTOP, NULL) ;
                    111:                     fCapture = FALSE ;
                    112:                     }
                    113:                return 0 ;
                    114: 
                    115:           case WM_PAINT:
                    116:                hps = WinBeginPaint (hwnd, NULL, NULL) ;
                    117:                GpiErase (hps) ;
                    118: 
                    119:                if (fValidBox)
                    120:                     {
                    121:                     GpiMove (hps, &ptlBoxStart) ;
                    122:                     GpiBox (hps, DRO_OUTLINEFILL, &ptlBoxEnd, 0L, 0L) ;
                    123:                     }
                    124:                if (fCapture)
                    125:                     {
                    126:                     GpiSetMix (hps, FM_INVERT) ;
                    127:                     GpiMove (hps, &ptlStart) ;
                    128:                     GpiBox (hps, DRO_OUTLINE, &ptlEnd, 0L, 0L) ;
                    129:                     }
                    130:                WinEndPaint (hps) ;
                    131:                return 0 ;
                    132:           }
                    133:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
                    134:      }

unix.superglobalmegacorp.com

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