Annotation of pmsdk/samples/petzold/chap09/sketch.c, revision 1.1

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

unix.superglobalmegacorp.com

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