Annotation of pmsdk/samples/petzold/chap06/hellobit.c, revision 1.1

1.1     ! root        1: /*-------------------------------------
        !             2:    HELLOBIT.C -- "Hello, world" Bitmap
        !             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 [] = "HelloBit" ;
        !            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:      WinSendMsg (hwndFrame, WM_SETICON,
        !            33:                  WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
        !            34:                  NULL) ;
        !            35: 
        !            36:      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
        !            37:           WinDispatchMsg (hab, &qmsg) ;
        !            38: 
        !            39:      WinDestroyWindow (hwndFrame) ;
        !            40:      WinDestroyMsgQueue (hmq) ;
        !            41:      WinTerminate (hab) ;
        !            42:      return 0 ;
        !            43:      }
        !            44: 
        !            45: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
        !            46:      {
        !            47:      static CHAR      szHello [] = " Hello, world " ;
        !            48:      static HBITMAP   hbm ;
        !            49:      static HDC       hdcMemory ;
        !            50:      static HPS       hpsMemory ;
        !            51:      static SHORT     cxClient, cyClient, cxString, cyString ;
        !            52:      BITMAPINFOHEADER bmp ;
        !            53:      HPS              hps ;
        !            54:      POINTL           aptl [4], ptl ;
        !            55:      SHORT            x, y ;
        !            56:      SIZEL            sizl ;
        !            57: 
        !            58:      switch (msg)
        !            59:           {
        !            60:           case WM_CREATE:
        !            61: 
        !            62:                          /*-------------------------------------------------
        !            63:                             Open memory DC and create PS associated with it
        !            64:                            -------------------------------------------------*/
        !            65: 
        !            66:                hdcMemory = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULL) ;
        !            67: 
        !            68:                sizl.cx = 0 ;
        !            69:                sizl.cy = 0 ;
        !            70:                hpsMemory = GpiCreatePS (hab, hdcMemory, &sizl,
        !            71:                                        PU_PELS    | GPIF_DEFAULT |
        !            72:                                         GPIT_MICRO | GPIA_ASSOC) ;
        !            73: 
        !            74:                          /*-------------------------------------
        !            75:                             Determine dimensions of text string
        !            76:                            -------------------------------------*/
        !            77: 
        !            78:                GpiQueryTextBox (hpsMemory, sizeof szHello - 1L,
        !            79:                                 szHello, 4L, aptl) ;
        !            80: 
        !            81:                cxString = (SHORT) (aptl [TXTBOX_TOPRIGHT].x -
        !            82:                                    aptl [TXTBOX_TOPLEFT].x) ;
        !            83: 
        !            84:                cyString = (SHORT) (aptl [TXTBOX_TOPLEFT].y -
        !            85:                                    aptl [TXTBOX_BOTTOMLEFT].y) ;
        !            86: 
        !            87:                          /*-------------------------------------------
        !            88:                             Create bitmap and set it in the memory PS
        !            89:                            -------------------------------------------*/
        !            90: 
        !            91:                bmp.cbFix     = sizeof bmp ;
        !            92:                bmp.cx        = cxString ;
        !            93:                bmp.cy        = cyString ;
        !            94:                bmp.cPlanes   = 1 ;
        !            95:                bmp.cBitCount = 1 ;
        !            96: 
        !            97:                hbm = GpiCreateBitmap (hpsMemory, &bmp, 0L, 0L, NULL) ;
        !            98: 
        !            99:                GpiSetBitmap (hpsMemory, hbm) ;
        !           100: 
        !           101:                          /*----------------------------------------
        !           102:                             Write the text string to the memory PS
        !           103:                            ----------------------------------------*/
        !           104: 
        !           105:                ptl.x = 0 ;
        !           106:                ptl.y = - aptl [TXTBOX_BOTTOMLEFT].y ;
        !           107: 
        !           108:                GpiSetColor (hpsMemory, CLR_TRUE) ;
        !           109:                GpiSetBackColor (hpsMemory, CLR_FALSE) ;
        !           110:                GpiSetBackMix (hpsMemory, BM_OVERPAINT) ;
        !           111:                GpiCharStringAt (hpsMemory, &ptl, sizeof szHello - 1L,
        !           112:                                 szHello) ;
        !           113:                return 0 ;
        !           114: 
        !           115:           case WM_SIZE:
        !           116:                cxClient = SHORT1FROMMP (mp2) ;
        !           117:                cyClient = SHORT2FROMMP (mp2) ;
        !           118:                return 0 ;
        !           119: 
        !           120:           case WM_PAINT:
        !           121:                hps = WinBeginPaint (hwnd, NULL, NULL) ;
        !           122: 
        !           123:                for (y = 0 ; y <= cyClient / cyString ; y++)
        !           124:                     for (x = 0 ; x <= cxClient / cxString ; x++)
        !           125:                          {
        !           126:                          aptl[0].x = x * cxString ;    // target lower left
        !           127:                          aptl[0].y = y * cyString ;
        !           128: 
        !           129:                          aptl[1].x = aptl[0].x + cxString ; // upper right
        !           130:                          aptl[1].y = aptl[0].y + cyString ;
        !           131: 
        !           132:                          aptl[2].x = 0 ;               // source lower left
        !           133:                          aptl[2].y = 0 ;
        !           134: 
        !           135:                          GpiBitBlt (hps, hpsMemory, 3L, aptl, ROP_SRCCOPY,
        !           136:                                     BBO_AND) ;
        !           137:                          }
        !           138:                WinEndPaint (hps) ;
        !           139:                return 0 ;
        !           140: 
        !           141:           case WM_DESTROY:
        !           142:                GpiDestroyPS (hpsMemory) ;
        !           143:                DevCloseDC (hdcMemory) ;
        !           144:                GpiDeleteBitmap (hbm) ;
        !           145:                return 0 ;
        !           146:           }
        !           147:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
        !           148:      }

unix.superglobalmegacorp.com

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