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