Annotation of pmsdk/samples/petzold/chap16/showbit.c, revision 1.1

1.1     ! root        1: /*--------------------------------------------------------------------
        !             2:    SHOWBIT.C -- Loads Bitmap Resources from BITLIB.DLL and Draws Them
        !             3:   --------------------------------------------------------------------*/
        !             4: 
        !             5: #define INCL_DOS
        !             6: #define INCL_WIN
        !             7: #include <os2.h>
        !             8: 
        !             9: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
        !            10: 
        !            11: int main (void)
        !            12:      {
        !            13:      static CHAR  szClientClass [] = "ShowBit" ;
        !            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,
        !            29:                                      " (Space bar or mouse click for next)",
        !            30:                                      0L, NULL, 0, &hwndClient) ;
        !            31:      if (hwndFrame != NULL)
        !            32:           {
        !            33:           while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
        !            34:                WinDispatchMsg (hab, &qmsg) ;
        !            35: 
        !            36:           WinDestroyWindow (hwndFrame) ;
        !            37:           }
        !            38:      WinDestroyMsgQueue (hmq) ;
        !            39:      WinTerminate (hab) ;
        !            40:      return 0 ;
        !            41:      }
        !            42: 
        !            43: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
        !            44:      {
        !            45:      static HMODULE hmodBitLib ;
        !            46:      static USHORT  idBitmap = 1 ;
        !            47:      HBITMAP        hbm ;
        !            48:      HPS            hps ;
        !            49:      RECTL          rcl ;
        !            50: 
        !            51:      switch (msg)
        !            52:           {
        !            53:           case WM_CREATE:
        !            54:                if (DosLoadModule (NULL, 0, "BITLIB", &hmodBitLib))
        !            55:                     {
        !            56:                     WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
        !            57:                                    "Cannot load BITLIB.DLL library",
        !            58:                                    "ShowBit", 0, MB_OK | MB_ICONEXCLAMATION) ;
        !            59:                     return 1 ;
        !            60:                     }
        !            61:                return 0 ;
        !            62: 
        !            63:           case WM_CHAR:
        !            64:                if (  CHARMSG(&msg)->fs & KC_KEYUP ||
        !            65:                    !(CHARMSG(&msg)->fs & KC_VIRTUALKEY) ||
        !            66:                    !(CHARMSG(&msg)->vkey == VK_SPACE))
        !            67:                          break ;
        !            68: 
        !            69:                if (++idBitmap == 10)
        !            70:                     idBitmap = 1 ;
        !            71: 
        !            72:                WinInvalidateRect (hwnd, NULL, FALSE) ;
        !            73:                return 0 ;
        !            74: 
        !            75:           case WM_BUTTON1DOWN:
        !            76:                if (++idBitmap == 10)
        !            77:                     idBitmap = 1 ;
        !            78: 
        !            79:                WinInvalidateRect (hwnd, NULL, FALSE) ;
        !            80:                break ;
        !            81: 
        !            82:           case WM_PAINT:
        !            83:                hps = WinBeginPaint (hwnd, NULL, NULL) ;
        !            84:                GpiErase (hps) ;
        !            85: 
        !            86:                hbm = GpiLoadBitmap (hps, hmodBitLib, idBitmap, 0L, 0L) ;
        !            87: 
        !            88:                if (hbm != NULL)
        !            89:                     {
        !            90:                     WinQueryWindowRect (hwnd, &rcl) ;
        !            91: 
        !            92:                     WinDrawBitmap (hps, hbm, NULL, (PPOINTL) &rcl,
        !            93:                                    CLR_NEUTRAL, CLR_BACKGROUND, DBM_STRETCH) ;
        !            94: 
        !            95:                     GpiDeleteBitmap (hbm) ;               
        !            96:                     }
        !            97:                WinEndPaint (hps) ;
        !            98:                return 0 ;
        !            99: 
        !           100:           case WM_DESTROY:
        !           101:                DosFreeModule (hmodBitLib) ;
        !           102:                return 0 ;
        !           103:           }
        !           104:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
        !           105:      }

unix.superglobalmegacorp.com

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