2 // ------------------------------------------------------------------
3 // Windows 2000 Graphics API Black Book
4 // Chapter 1 - Listing 1.3 (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.
11 // ------------------------------------------------------------------
14 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
16 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
20 const char* WndClassName = "GMainWnd";
21 LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
25 int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance,
26 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, IDC_ARROW);
37 wc.hbrBackground = reinterpret_cast<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);
57 while (GetMessage(&msg, NULL, 0, 0))
59 TranslateMessage(&msg);
60 DispatchMessage(&msg);
66 //------------------------------------------------------------------
71 LPCSTR filename = TEXT("lena.bmp");
73 HBITMAP HOldBmp = NULL;
75 LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
83 HMemDC = CreateCompatibleDC(NULL);
86 // load a bitmap from file
89 LoadImage(HInst, filename, IMAGE_BITMAP,
90 0, 0, LR_LOADFROMFILE)
94 // extract dimensions of the bitmap
95 GetObject(HBmp, sizeof(BITMAP), &bmp);
97 // associate the bitmap with the memory DC
98 HOldBmp = static_cast<HBITMAP>(
99 SelectObject(HMemDC, HBmp)
107 const HDC Hdc = BeginPaint(HWnd, &ps);
111 // TODO: add palette support (see Chapter 9)...
115 bmp.bmWidth, bmp.bmHeight,
129 DeleteObject(SelectObject(HMemDC, HOldBmp));
136 return DefWindowProc(HWnd, Msg, WParam, LParam);
138 //------------------------------------------------------------------