[USER32]
[reactos.git] / rostests / dibtests / bltrop / bltrop.c
1 /*
2 * Shows the 15 well known BitBlt raster operations
3 * using src, dest, pattern, a background brush and color.
4 *
5 * Created by Gregor Schneider <grschneider AT gmail DOT com>, November 2008
6 */
7
8 #include <windows.h>
9 #include <tchar.h>
10
11 HINSTANCE hInst;
12 TCHAR szWindowClass[] = _T("testclass");
13
14 static LRESULT CALLBACK
15 WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
16 {
17 static HBITMAP hBmpTest;
18
19 switch (message)
20 {
21 case WM_CREATE:
22 {
23 hBmpTest = (HBITMAP)LoadImage(hInst, MAKEINTRESOURCE(100), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
24 break;
25 }
26
27 case WM_PAINT:
28 {
29 PAINTSTRUCT ps;
30 HDC hdc, hdcMem;
31 BITMAP bitmap;
32 HBRUSH brush, brush2;
33 INT l;
34
35 hdc = BeginPaint(hWnd, &ps);
36 hdcMem = CreateCompatibleDC(hdc);
37
38 GetObject(hBmpTest, sizeof(BITMAP), &bitmap);
39
40 /* fill destination with brush */
41 brush = CreateHatchBrush(HS_DIAGCROSS, RGB(255,0,0));
42 SelectObject(hdc, brush);
43 PatBlt(hdc, 30, 0, 4*bitmap.bmWidth*2, 4*bitmap.bmHeight, PATCOPY);
44
45 /* hatched brushes */
46 l = 66;
47 brush = CreateHatchBrush(HS_DIAGCROSS, RGB(255,0,0));
48 SelectObject(hdc, brush);
49 PatBlt(hdc, 0, 0, 30, l, PATCOPY);
50 DeleteObject(brush);
51
52 brush = CreateHatchBrush(HS_CROSS, RGB(255,0,0));
53 SelectObject(hdc, brush);
54 PatBlt(hdc, 0, 1*l, 30, l, PATCOPY);
55 DeleteObject(brush);
56
57 brush = CreateHatchBrush(HS_FDIAGONAL, RGB(255,0,0));
58 SelectObject(hdc, brush);
59 PatBlt(hdc, 0, 2*l, 30, l, PATCOPY);
60 DeleteObject(brush);
61
62 brush = CreateHatchBrush(HS_BDIAGONAL, RGB(255,0,0));
63 SelectObject(hdc, brush);
64 PatBlt(hdc, 0, 3*l, 30, l, PATCOPY);
65 DeleteObject(brush);
66
67 brush = CreateHatchBrush(HS_VERTICAL, RGB(255,0,0));
68 SelectObject(hdc, brush);
69 PatBlt(hdc, 0, 4*l, 30, l, PATCOPY);
70 DeleteObject(brush);
71
72 brush = CreateHatchBrush(HS_HORIZONTAL, RGB(255,0,0));
73 SelectObject(hdc, brush);
74 PatBlt(hdc, 0, 5*l, 30, l, PATCOPY);
75 DeleteObject(brush);
76
77 /* set up a second brush */
78 brush2 = CreateHatchBrush(HS_VERTICAL, RGB(127,127,127));
79
80 /* first select brush, then set bk color */
81 SelectObject(hdc, brush2);
82 SetBkColor(hdc, RGB(0, 255, 0));
83
84 /* 15 blt op's with bitblt */
85 SelectObject(hdcMem, hBmpTest);
86 /* offset coordinates */
87 SetWindowOrgEx(hdc, -10, -10, NULL);
88 BitBlt(hdc, 30, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
89 BitBlt(hdc, 130, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, DSTINVERT);
90 BitBlt(hdc, 230, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, MERGECOPY);
91 BitBlt(hdc, 330, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, MERGEPAINT);
92
93 BitBlt(hdc, 30, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, NOTSRCCOPY);
94 BitBlt(hdc, 130, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, NOTSRCERASE);
95 BitBlt(hdc, 230, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, PATCOPY);
96 BitBlt(hdc, 330, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, PATINVERT);
97
98 BitBlt(hdc, 30, 200, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, PATPAINT);
99 BitBlt(hdc, 130, 200, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCAND);
100 BitBlt(hdc, 230, 200, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCERASE);
101 BitBlt(hdc, 330, 200, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCINVERT);
102
103 BitBlt(hdc, 30, 300, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, BLACKNESS);
104 BitBlt(hdc, 130, 300, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCPAINT);
105 BitBlt(hdc, 230, 300, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, WHITENESS);
106
107 /* 15 blt op's with stretchblt */
108 StretchBlt(hdc, 30+400, 0, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
109 StretchBlt(hdc, 130+400, 0, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, DSTINVERT);
110 StretchBlt(hdc, 230+400, 0, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, MERGECOPY);
111 StretchBlt(hdc, 330+400, 0, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, MERGEPAINT);
112
113 StretchBlt(hdc, 30+400, 100, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, NOTSRCCOPY);
114 StretchBlt(hdc, 130+400, 100, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, NOTSRCERASE);
115 StretchBlt(hdc, 230+400, 100, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, PATCOPY);
116 StretchBlt(hdc, 330+400, 100, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, PATINVERT);
117
118 StretchBlt(hdc, 30+400, 200, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, PATPAINT);
119 StretchBlt(hdc, 130+400, 200, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCAND);
120 StretchBlt(hdc, 230+400, 200, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCERASE);
121 StretchBlt(hdc, 330+400, 200, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCINVERT);
122
123 StretchBlt(hdc, 30+400, 300, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, BLACKNESS);
124 StretchBlt(hdc, 130+400, 300, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCPAINT);
125 StretchBlt(hdc, 230+400, 300, bitmap.bmWidth/2, bitmap.bmHeight/2, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, WHITENESS);
126
127 DeleteObject(brush);
128 DeleteObject(brush2);
129 DeleteDC(hdcMem);
130 EndPaint(hWnd, &ps);
131 break;
132 }
133
134 case WM_DESTROY:
135 PostQuitMessage(0);
136 break;
137 default:
138 return DefWindowProc(hWnd, message, wParam, lParam);
139 }
140 return 0;
141 }
142
143
144 static ATOM
145 MyRegisterClass(HINSTANCE hInstance)
146 {
147 WNDCLASSEX wcex;
148
149 wcex.cbSize = sizeof(WNDCLASSEX);
150
151 wcex.style = CS_HREDRAW | CS_VREDRAW;
152 wcex.lpfnWndProc = WndProc;
153 wcex.cbClsExtra = 0;
154 wcex.cbWndExtra = 0;
155 wcex.hInstance = hInstance;
156 wcex.hIcon = NULL;
157 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
158 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
159 wcex.lpszMenuName = NULL;
160 wcex.lpszClassName = szWindowClass;
161 wcex.hIconSm = NULL;
162
163 return RegisterClassEx(&wcex);
164 }
165
166
167 static BOOL
168 InitInstance(HINSTANCE hInstance, int nCmdShow)
169 {
170 HWND hWnd;
171
172 hInst = hInstance;
173
174 hWnd = CreateWindowEx(0,
175 szWindowClass,
176 _T("BitBlt raster operation test"),
177 WS_OVERLAPPEDWINDOW,
178 CW_USEDEFAULT,
179 CW_USEDEFAULT,
180 840,
181 440,
182 NULL,
183 NULL,
184 hInstance,
185 NULL);
186
187 if (!hWnd)
188 {
189 return FALSE;
190 }
191
192 ShowWindow(hWnd, nCmdShow);
193 UpdateWindow(hWnd);
194
195 return TRUE;
196 }
197
198
199 int WINAPI
200 _tWinMain(HINSTANCE hInstance,
201 HINSTANCE hPrevInstance,
202 LPTSTR lpCmdLine,
203 int nCmdShow)
204 {
205 MSG msg;
206
207 MyRegisterClass(hInstance);
208
209 if (!InitInstance(hInstance, nCmdShow))
210 {
211 return FALSE;
212 }
213
214 while (GetMessage(&msg, NULL, 0, 0))
215 {
216 TranslateMessage(&msg);
217 DispatchMessage(&msg);
218 }
219
220 return (int)msg.wParam;
221 }