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

1.1       root        1: /*----------------------------------------
                      2:    SCRIBBLE.C -- Mouse Scribbling Program 
                      3:   ----------------------------------------*/
                      4: 
                      5: #define INCL_WIN
                      6: #define INCL_GPI
                      7: 
                      8: #include <os2.h>
                      9: #include <stddef.h>
                     10: 
                     11: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
                     12: 
                     13: HAB  hab ;
                     14: 
                     15: int main (void)
                     16:      {
                     17:      static CHAR szClientClass [] = "Scribble" ;
                     18:      HMQ         hmq ;
                     19:      HWND        hwndFrame, hwndClient ;
                     20:      QMSG        qmsg ;
                     21:      ULONG       flFrameFlags = FCF_STANDARD & ~FCF_MENU ;
                     22:      ULONG       flFrameStyle = WS_VISIBLE ;
                     23: 
                     24:      hab = WinInitialize (0) ;
                     25:      hmq = WinCreateMsgQueue (hab, 0) ;
                     26: 
                     27:      WinRegisterClass (hab, szClientClass, ClientWndProc, 0L, 0) ;
                     28: 
                     29:      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, flFrameStyle,
                     30:                                      &flFrameFlags, szClientClass,
                     31:                                      szClientClass,
                     32:                                     0L, NULL, 0, &hwndClient) ;
                     33: 
                     34:      if (hwndClient == NULL)
                     35:           WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
                     36:                          "Not enough memory to create the "
                     37:                          "bitmap used for storing images.",
                     38:                          szClientClass, 0, MB_OK | MB_ICONEXCLAMATION) ;
                     39:      else
                     40:           {
                     41:           while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
                     42:                WinDispatchMsg (hab, &qmsg) ;
                     43: 
                     44:           WinDestroyWindow (hwndFrame) ;
                     45:           }
                     46: 
                     47:      WinDestroyMsgQueue (hmq) ;
                     48:      WinTerminate (hab) ;
                     49:      
                     50:      return 0 ;
                     51:      }
                     52: 
                     53: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
                     54:      {
                     55:      static BOOL      fButton1Down, fButton2Down ;
                     56:      static HBITMAP   hbm ;
                     57:      static HDC       hdcMemory ;
                     58:      static HPS       hpsMemory ;
                     59:      static POINTL    ptlPointerPos, aptl [3] ;
                     60:      BITMAPINFOHEADER bmp ;
                     61:      HPS              hpsWindow ;
                     62:      LONG             cxFullScrn, cyFullScrn ;
                     63:      SIZEL            sizl ;
                     64: 
                     65:      switch (msg)
                     66:           {
                     67:           case WM_CREATE:
                     68:                cxFullScrn = WinQuerySysValue (HWND_DESKTOP, SV_CXFULLSCREEN) ;
                     69:                cyFullScrn = WinQuerySysValue (HWND_DESKTOP, SV_CYFULLSCREEN) ;
                     70: 
                     71:                          /*-------------------------
                     72:                             Create Memory DC and PS
                     73:                            -------------------------*/
                     74: 
                     75:                hdcMemory = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULL) ;
                     76: 
                     77:                sizl.cx = 0 ;
                     78:                sizl.cy = 0 ;
                     79:                hpsMemory = GpiCreatePS (hab, hdcMemory, &sizl,
                     80:                                        PU_PELS    | GPIF_DEFAULT |
                     81:                                         GPIT_MICRO | GPIA_ASSOC) ;
                     82: 
                     83:                          /*----------------------------------------------
                     84:                             Create monochrome bitmap, return 1 if cannot
                     85:                            ----------------------------------------------*/
                     86: 
                     87:                bmp.cx = (SHORT) cxFullScrn ;
                     88:                bmp.cy = (SHORT) cyFullScrn ;
                     89:                bmp.cPlanes = 1 ;
                     90:                bmp.cBitCount = 1 ;
                     91:                hbm = GpiCreateBitmap (hpsMemory, &bmp, 0L, 0L, NULL) ;
                     92: 
                     93:                if (hbm == NULL)
                     94:                     {
                     95:                     GpiDestroyPS (hpsMemory) ;
                     96:                     DevCloseDC (hdcMemory) ;
                     97:                     return 1 ;
                     98:                     }
                     99: 
                    100:                          /*--------------------------------------
                    101:                             Set bitmap in memory PS and clear it
                    102:                            --------------------------------------*/
                    103: 
                    104:                GpiSetBitmap (hpsMemory, hbm) ;
                    105: 
                    106:                aptl[1].x = cxFullScrn ;
                    107:                aptl[1].y = cyFullScrn ;
                    108:                GpiBitBlt (hpsMemory, NULL, 2L, aptl, ROP_ZERO, BBO_OR) ;
                    109:                return 0 ;
                    110: 
                    111:           case WM_BUTTON1DOWN:
                    112:                if (!fButton2Down)
                    113:                     WinSetCapture (HWND_DESKTOP, hwnd) ;
                    114: 
                    115:                ptlPointerPos.x = MOUSEMSG(&msg)->x ;
                    116:                ptlPointerPos.y = MOUSEMSG(&msg)->y ;
                    117: 
                    118:                fButton1Down = TRUE ;
                    119:                return 1 ;
                    120: 
                    121:           case WM_BUTTON1UP:
                    122:                if (!fButton2Down)
                    123:                     WinSetCapture (HWND_DESKTOP, NULL) ;
                    124: 
                    125:                fButton1Down = FALSE ;
                    126:                return 1 ;
                    127: 
                    128:           case WM_BUTTON2DOWN:
                    129:                if (!fButton1Down)
                    130:                     WinSetCapture (HWND_DESKTOP, hwnd) ;
                    131: 
                    132:                ptlPointerPos.x = MOUSEMSG(&msg)->x ;
                    133:                ptlPointerPos.y = MOUSEMSG(&msg)->y ;
                    134: 
                    135:                fButton2Down = TRUE ;
                    136:                return 1 ;
                    137: 
                    138:           case WM_BUTTON2UP:
                    139:                if (!fButton1Down)
                    140:                     WinSetCapture (HWND_DESKTOP, NULL) ;
                    141: 
                    142:                fButton2Down = FALSE ;
                    143:                return 1 ;
                    144: 
                    145:           case WM_MOUSEMOVE:
                    146:                if (!fButton1Down && !fButton2Down)
                    147:                     break ;
                    148: 
                    149:                hpsWindow = WinGetPS (hwnd) ;
                    150: 
                    151:                GpiSetColor (hpsMemory, fButton1Down ? CLR_TRUE : CLR_FALSE) ;
                    152:                GpiSetColor (hpsWindow,
                    153:                             fButton1Down ? CLR_NEUTRAL : CLR_BACKGROUND) ;
                    154: 
                    155:                GpiMove (hpsMemory, &ptlPointerPos) ;
                    156:                GpiMove (hpsWindow, &ptlPointerPos) ;
                    157: 
                    158:                ptlPointerPos.x = MOUSEMSG(&msg)->x ;
                    159:                ptlPointerPos.y = MOUSEMSG(&msg)->y ;
                    160: 
                    161:                GpiLine (hpsMemory, &ptlPointerPos) ;
                    162:                GpiLine (hpsWindow, &ptlPointerPos) ;
                    163: 
                    164:                WinReleasePS (hpsWindow) ;
                    165:                return 1 ;
                    166: 
                    167:           case WM_PAINT:
                    168:                hpsWindow = WinBeginPaint (hwnd, NULL, (PRECTL) aptl) ;
                    169: 
                    170:                aptl[2] = aptl[0] ;
                    171: 
                    172:                GpiBitBlt (hpsWindow, hpsMemory, 3L, aptl, ROP_SRCCOPY,
                    173:                           BBO_OR) ;
                    174: 
                    175:                WinEndPaint (hpsWindow) ;
                    176:                return 0 ;
                    177: 
                    178:           case WM_DESTROY:
                    179:                GpiDestroyPS (hpsMemory) ;
                    180:                DevCloseDC (hdcMemory) ;
                    181:                GpiDeleteBitmap (hbm) ;
                    182:                return 0 ;
                    183:           }
                    184:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
                    185:      }

unix.superglobalmegacorp.com

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