3 * Windows 2000 Graphics API Black Book
4 * (BitBlt Bitmap Rendering Demo)
6 * Created by Damon Chandler <dmc27@ee.cornell.edu>
7 * Updates can be downloaded at: <www.coriolis.com>
9 * Please do not hesistate to e-mail me at dmc27@ee.cornell.edu
10 * if you have any questions about this code.
17 const char* WndClassName
= "GMainWnd";
18 LRESULT CALLBACK
MainWndProc(HWND HWnd
, UINT Msg
, WPARAM WParam
,
22 int APIENTRY
WinMain(HINSTANCE HInstance
, HINSTANCE HPrevInstance
,
23 LPTSTR lpCmdLine
, int nCmdShow
)
30 memset(&wc
, 0, sizeof(WNDCLASS
));
32 wc
.style
= CS_VREDRAW
| CS_HREDRAW
| CS_DBLCLKS
;
33 wc
.lpfnWndProc
= MainWndProc
;
34 wc
.hInstance
= HInstance
;
35 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
36 /* wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1); */
37 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
38 wc
.lpszClassName
= WndClassName
;
40 if (RegisterClass(&wc
))
44 WndClassName
, TEXT("BitBlt Bitmap Rendering Demo"),
45 WS_OVERLAPPED
| WS_SYSMENU
| WS_CAPTION
|
46 WS_VISIBLE
| WS_CLIPSIBLINGS
,
48 NULL
, NULL
, HInst
, NULL
53 ShowWindow(HWnd
, nCmdShow
);
56 while (GetMessage(&msg
, NULL
, 0, 0))
58 TranslateMessage(&msg
);
59 DispatchMessage(&msg
);
68 LPCSTR filename
= TEXT("lena.bmp");
70 HBITMAP HOldBmp
= NULL
;
72 LRESULT CALLBACK
MainWndProc(HWND HWnd
, UINT Msg
, WPARAM WParam
,
79 /* create a memory DC */
80 HMemDC
= CreateCompatibleDC(NULL
);
83 /* load a bitmap from file */
85 /* static_cast<HBITMAP> */(
86 LoadImage(HInst
, filename
, IMAGE_BITMAP
,
87 0, 0, LR_LOADFROMFILE
)
91 /* extract dimensions of the bitmap */
92 GetObject(HBmp
, sizeof(BITMAP
), &bmp
);
94 /* associate the bitmap with the memory DC */
95 /* HOldBmp = static_cast<HBITMAP> */
96 (SelectObject(HMemDC
, HBmp
)
104 const HDC Hdc
= BeginPaint(HWnd
, &ps
);
110 /* TODO: add palette support (see Chapter 9)... */
114 bmp
.bmWidth
, bmp
.bmHeight
,
130 DeleteObject(SelectObject(HMemDC
, HOldBmp
));
137 return DefWindowProc(HWnd
, Msg
, WParam
, LParam
);