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.
18 const char* WndClassName
= "GMainWnd";
19 LRESULT CALLBACK
MainWndProc(HWND HWnd
, UINT Msg
, WPARAM WParam
,
23 int APIENTRY
WinMain(HINSTANCE HInstance
, HINSTANCE HPrevInstance
,
24 LPTSTR lpCmdLine
, int nCmdShow
)
31 memset(&wc
, 0, sizeof(WNDCLASS
));
33 wc
.style
= CS_VREDRAW
| CS_HREDRAW
| CS_DBLCLKS
;
34 wc
.lpfnWndProc
= MainWndProc
;
35 wc
.hInstance
= HInstance
;
36 wc
.hCursor
= LoadCursor(NULL
, (LPCTSTR
)IDC_ARROW
);
37 /* wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1); */
38 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
39 wc
.lpszClassName
= WndClassName
;
41 if (RegisterClass(&wc
))
45 WndClassName
, TEXT("BitBlt Bitmap Rendering Demo"),
46 WS_OVERLAPPED
| WS_SYSMENU
| WS_CAPTION
|
47 WS_VISIBLE
| WS_CLIPSIBLINGS
,
49 NULL
, NULL
, HInst
, NULL
54 ShowWindow(HWnd
, nCmdShow
);
57 while (GetMessage(&msg
, NULL
, 0, 0))
59 TranslateMessage(&msg
);
60 DispatchMessage(&msg
);
69 LPCSTR filename
= TEXT("lena.bmp");
71 HBITMAP HOldBmp
= NULL
;
73 LRESULT CALLBACK
MainWndProc(HWND HWnd
, UINT Msg
, WPARAM WParam
,
80 /* create a memory DC */
81 HMemDC
= CreateCompatibleDC(NULL
);
84 /* load a bitmap from file */
86 /* static_cast<HBITMAP> */(
87 LoadImage(HInst
, MAKEINTRESOURCE(1000), IMAGE_BITMAP
,
92 /* extract dimensions of the bitmap */
93 GetObject(HBmp
, sizeof(BITMAP
), &bmp
);
95 /* associate the bitmap with the memory DC */
96 /* HOldBmp = static_cast<HBITMAP> */
97 (SelectObject(HMemDC
, HBmp
)
105 const HDC Hdc
= BeginPaint(HWnd
, &ps
);
111 /* TODO: add palette support (see Chapter 9)... */
115 bmp
.bmWidth
, bmp
.bmHeight
,
131 DeleteObject(SelectObject(HMemDC
, HOldBmp
));
138 return DefWindowProc(HWnd
, Msg
, WParam
, LParam
);