- Fix warnings in ros' tests
[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, 0, 0, 4*bitmap.bmWidth, 4*bitmap.bmHeight, PATCOPY);
43 /* set up a second brush */
44 brush2 = CreateHatchBrush(HS_VERTICAL, RGB(127,127,127));
45
46 /* first select brush, then set bk color */
47 SelectObject(hdc, brush2);
48 SetBkColor(hdc, RGB(0, 255, 0));
49
50 /* 15 blt op's */
51 SelectObject(hdcMem, hBmpTest);
52 BitBlt(hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
53 BitBlt(hdc, 100, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, DSTINVERT);
54 BitBlt(hdc, 200, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, MERGECOPY);
55 BitBlt(hdc, 300, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, MERGEPAINT);
56
57 BitBlt(hdc, 0, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, NOTSRCCOPY);
58 BitBlt(hdc, 100, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, NOTSRCERASE);
59 BitBlt(hdc, 200, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, PATCOPY);
60 BitBlt(hdc, 300, 100, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, PATINVERT);
61
62 BitBlt(hdc, 0, 200, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, PATPAINT);
63 BitBlt(hdc, 100, 200, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCAND);
64 BitBlt(hdc, 200, 200, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCERASE);
65 BitBlt(hdc, 300, 200, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCINVERT);
66
67 BitBlt(hdc, 0, 300, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, BLACKNESS);
68 BitBlt(hdc, 100, 300, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCPAINT);
69 BitBlt(hdc, 200, 300, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, WHITENESS);
70
71 DeleteDC(hdcMem);
72 EndPaint(hWnd, &ps);
73 break;
74 }
75
76 case WM_DESTROY:
77 PostQuitMessage(0);
78 break;
79 default:
80 return DefWindowProc(hWnd, message, wParam, lParam);
81 }
82 return 0;
83 }
84
85
86 static ATOM
87 MyRegisterClass(HINSTANCE hInstance)
88 {
89 WNDCLASSEX wcex;
90
91 wcex.cbSize = sizeof(WNDCLASSEX);
92
93 wcex.style = CS_HREDRAW | CS_VREDRAW;
94 wcex.lpfnWndProc = WndProc;
95 wcex.cbClsExtra = 0;
96 wcex.cbWndExtra = 0;
97 wcex.hInstance = hInstance;
98 wcex.hIcon = NULL;
99 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
100 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
101 wcex.lpszMenuName = NULL;
102 wcex.lpszClassName = szWindowClass;
103 wcex.hIconSm = NULL;
104
105 return RegisterClassEx(&wcex);
106 }
107
108
109 static BOOL
110 InitInstance(HINSTANCE hInstance, int nCmdShow)
111 {
112 HWND hWnd;
113
114 hInst = hInstance;
115
116 hWnd = CreateWindowEx(0,
117 szWindowClass,
118 _T("BitBlt raster operation test"),
119 WS_OVERLAPPEDWINDOW,
120 CW_USEDEFAULT,
121 CW_USEDEFAULT,
122 440,
123 440,
124 NULL,
125 NULL,
126 hInstance,
127 NULL);
128
129 if (!hWnd)
130 {
131 return FALSE;
132 }
133
134 ShowWindow(hWnd, nCmdShow);
135 UpdateWindow(hWnd);
136
137 return TRUE;
138 }
139
140
141 int WINAPI
142 _tWinMain(HINSTANCE hInstance,
143 HINSTANCE hPrevInstance,
144 LPTSTR lpCmdLine,
145 int nCmdShow)
146 {
147 MSG msg;
148
149 MyRegisterClass(hInstance);
150
151 if (!InitInstance(hInstance, nCmdShow))
152 {
153 return FALSE;
154 }
155
156 while (GetMessage(&msg, NULL, 0, 0))
157 {
158 TranslateMessage(&msg);
159 DispatchMessage(&msg);
160 }
161
162 return (int)msg.wParam;
163 }