2003-07-11 Casper S. Hornstrup <chorns@users.sourceforge.net>
[reactos.git] / reactos / apps / tests / bitblt / bitblt.c
1
2 /*
3 * Windows 2000 Graphics API Black Book
4 * (BitBlt Bitmap Rendering Demo)
5 *
6 * Created by Damon Chandler <dmc27@ee.cornell.edu>
7 * Updates can be downloaded at: <www.coriolis.com>
8 *
9 * Please do not hesistate to e-mail me at dmc27@ee.cornell.edu
10 * if you have any questions about this code.
11 */
12
13
14 #include <windows.h>
15
16 HINSTANCE HInst;
17 const char* WndClassName = "GMainWnd";
18 LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
19 LPARAM LParam);
20
21
22 int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance,
23 LPTSTR lpCmdLine, int nCmdShow)
24 {
25 WNDCLASS wc;
26 MSG msg;
27
28 HInst = HInstance;
29
30 memset(&wc, 0, sizeof(WNDCLASS));
31
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;
39
40 if (RegisterClass(&wc))
41 {
42 HWND HWnd =
43 CreateWindow(
44 WndClassName, TEXT("BitBlt Bitmap Rendering Demo"),
45 WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION |
46 WS_VISIBLE | WS_CLIPSIBLINGS,
47 0, 0, 220, 230,
48 NULL, NULL, HInst, NULL
49 );
50
51 if (HWnd)
52 {
53 ShowWindow(HWnd, nCmdShow);
54 UpdateWindow(HWnd);
55
56 while (GetMessage(&msg, NULL, 0, 0))
57 {
58 TranslateMessage(&msg);
59 DispatchMessage(&msg);
60 }
61 }
62 }
63 return 0;
64 }
65
66 /* image related */
67 BITMAP bmp;
68 LPCSTR filename = TEXT("lena.bmp");
69 HDC HMemDC = NULL;
70 HBITMAP HOldBmp = NULL;
71
72 LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
73 LPARAM LParam)
74 {
75 switch (Msg)
76 {
77 case WM_CREATE:
78 {
79 /* create a memory DC */
80 HMemDC = CreateCompatibleDC(NULL);
81 if (HMemDC)
82 {
83 /* load a bitmap from file */
84 HBITMAP HBmp =
85 /* static_cast<HBITMAP> */(
86 LoadImage(HInst, filename, IMAGE_BITMAP,
87 0, 0, LR_LOADFROMFILE)
88 );
89 if (HBmp)
90 {
91 /* extract dimensions of the bitmap */
92 GetObject(HBmp, sizeof(BITMAP), &bmp);
93
94 /* associate the bitmap with the memory DC */
95 /* HOldBmp = static_cast<HBITMAP> */
96 (SelectObject(HMemDC, HBmp)
97 );
98 }
99 }
100 }
101 case WM_PAINT:
102 {
103 PAINTSTRUCT ps;
104 const HDC Hdc = BeginPaint(HWnd, &ps);
105 #if 0
106 try
107 #endif
108 {
109
110 /* TODO: add palette support (see Chapter 9)... */
111
112
113 BitBlt(Hdc, 20, 15,
114 bmp.bmWidth, bmp.bmHeight,
115 HMemDC, 0, 0,
116 SRCCOPY);
117 }
118 #if 0
119 catch (...)
120 #endif
121 {
122 EndPaint(HWnd, &ps);
123 }
124 EndPaint(HWnd, &ps);
125 break;
126 }
127 case WM_DESTROY:
128 {
129 /* clean up */
130 DeleteObject(SelectObject(HMemDC, HOldBmp));
131 DeleteDC(HMemDC);
132
133 PostQuitMessage(0);
134 return 0;
135 }
136 }
137 return DefWindowProc(HWnd, Msg, WParam, LParam);
138 }