home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prog_pm / chap12 / loadbmp1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-09  |  2.3 KB  |  75 lines

  1. /*----------------------------------------------------
  2.    LOADBMP1.C -- Loads a Bitmap Resource and Draws it
  3.   ----------------------------------------------------*/
  4.  
  5. #define INCL_WIN
  6. #include <os2.h>
  7. #include "loadbmp.h"
  8.  
  9. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  10.  
  11. int main (void)
  12.      {
  13.      static CHAR  szClientClass [] = "LoadBmp1" ;
  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.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  32.           WinDispatchMsg (hab, &qmsg) ;
  33.  
  34.      WinDestroyWindow (hwndFrame) ;
  35.      WinDestroyMsgQueue (hmq) ;
  36.      WinTerminate (hab) ;
  37.      return 0 ;
  38.      }
  39.  
  40. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  41.      {
  42.      static SHORT cxClient, cyClient ;
  43.      HBITMAP      hbm ;
  44.      HPS          hps ;
  45.      POINTL       ptl ;
  46.  
  47.      switch (msg)
  48.           {
  49.           case WM_SIZE:
  50.                cxClient = SHORT1FROMMP (mp2) ;
  51.                cyClient = SHORT2FROMMP (mp2) ;
  52.                return 0 ;
  53.  
  54.           case WM_PAINT:
  55.                hps = WinBeginPaint (hwnd, NULL, NULL) ;
  56.                GpiErase (hps) ;
  57.  
  58.                hbm = GpiLoadBitmap (hps, NULL, IDB_HELLO,
  59.                                     (LONG) cxClient, (LONG) cyClient) ;
  60.                if (hbm)
  61.                     {
  62.                     ptl.x = 0 ;
  63.                     ptl.y = 0 ;
  64.  
  65.                     WinDrawBitmap (hps, hbm, NULL, &ptl,
  66.                                    CLR_NEUTRAL, CLR_BACKGROUND, DBM_NORMAL) ;
  67.  
  68.                     GpiDeleteBitmap (hbm) ;               
  69.                     }
  70.                WinEndPaint (hps) ;
  71.                return 0 ;
  72.           }
  73.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  74.      }
  75.