2e31ee4e748e666671902417044d5362b72ce656
[reactos.git] / rostests / win32 / user32 / drawcaption / drawcap.c
1 /*
2 * Copyright 2006 Saveliy Tretiakov
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include "windows.h"
20 #include "resource.h"
21 #include "stdio.h"
22
23 WCHAR CaptWndClass[] = L"captwnd_class";
24
25 HINSTANCE hInst;
26 INT testnum = 0;
27
28 //BOOL WINAPI (*DrawCaptionTemp) (
29 // HWND hwnd,
30 // HDC hdc,
31 // const RECT *rect,
32 // HFONT hFont,
33 // HICON hIcon,
34 // LPCWSTR str,
35 // UINT uFlags);
36
37 VOID CapTest(HWND hWnd,
38 HDC hDc,
39 LPRECT pR,
40 WCHAR *Text,
41 DWORD Flags,
42 WCHAR *AddonStr,
43 DWORD Addon)
44 {
45 WCHAR Buf[512];
46
47 lstrcpy(Buf, AddonStr);
48 if(lstrlen(Buf))lstrcat(Buf, L" | ");
49 lstrcat(Buf, Text);
50
51 DrawText( hDc, Buf, lstrlen(Buf), pR, DT_LEFT );
52
53 pR->top+=20;
54 pR->bottom+=20;
55
56 if(!DrawCaption(hWnd, hDc, pR, Flags | Addon))
57 {
58 printf("PAINT: DrawCaption failed: %d\n", (int)GetLastError());
59 }
60
61 pR->top+=30;
62 pR->bottom+=30;
63 }
64
65 VOID DrawCaptionTest(HWND hWnd, HDC hDc, WCHAR *AddonStr, DWORD Addon)
66 {
67 RECT Rect;
68 GetClientRect(hWnd, &Rect);
69 Rect.bottom = 30;
70 Rect.left = 10;
71 Rect.right-=10;
72 Rect.top = 10;
73
74 CapTest(hWnd, hDc, &Rect, L"DC_TEXT:", DC_TEXT, AddonStr, Addon);
75
76 CapTest(hWnd, hDc, &Rect,
77 L"DC_TEXT | DC_ACTIVE:",
78 DC_TEXT | DC_ACTIVE,
79 AddonStr, Addon);
80
81 CapTest(hWnd, hDc, &Rect,
82 L"DC_TEXT | DC_ICON:" ,
83 DC_TEXT | DC_ICON,
84 AddonStr, Addon);
85
86 CapTest(hWnd, hDc, &Rect,
87 L"DC_TEXT | DC_ACTIVE | DC_ICON:" ,
88 DC_TEXT | DC_ACTIVE | DC_ICON,
89 AddonStr, Addon);
90
91 CapTest(hWnd, hDc, &Rect,
92 L"DC_TEXT | DC_INBUTTON:" ,
93 DC_TEXT | DC_INBUTTON,
94 AddonStr, Addon);
95
96 CapTest(hWnd, hDc, &Rect,
97 L"DC_TEXT | DC_ACTIVE | DC_INBUTTON:" ,
98 DC_TEXT | DC_ACTIVE | DC_INBUTTON,
99 AddonStr, Addon);
100
101 CapTest(hWnd, hDc, &Rect,
102 L"DC_TEXT | DC_ICON | DC_INBUTTON:" ,
103 DC_TEXT | DC_ICON | DC_INBUTTON,
104 AddonStr, Addon);
105
106 CapTest(hWnd, hDc, &Rect,
107 L"DC_TEXT | DC_ACTIVE | DC_ICON | DC_INBUTTON:" ,
108 DC_TEXT | DC_ACTIVE | DC_ICON | DC_INBUTTON,
109 AddonStr, Addon);
110
111 }
112
113 LRESULT CALLBACK CaptWndProc(HWND hWnd,
114 UINT msg,
115 WPARAM wParam,
116 LPARAM lParam)
117 {
118
119
120 switch (msg)
121 {
122
123 case WM_PAINT:
124 {
125 HDC hDc;
126 PAINTSTRUCT Ps;
127
128 hDc = BeginPaint(hWnd, &Ps);
129 SetBkMode( hDc, TRANSPARENT );
130
131 switch(testnum)
132 {
133 case 1:
134 DrawCaptionTest(hWnd, hDc, L"", 0);
135 break;
136 case 2:
137 DrawCaptionTest(hWnd, hDc, L"DC_GRADIENT", DC_GRADIENT);
138 break;
139 case 3:
140 DrawCaptionTest(hWnd, hDc, L"DC_SMALLCAP", DC_SMALLCAP);
141 break;
142 case 4:
143 DrawCaptionTest(hWnd, hDc, L"DC_BUTTONS", DC_BUTTONS);
144 break;
145 case 5:
146 DrawCaptionTest(hWnd, hDc,
147 L"DC_GRADIENT | DC_SMALLCAP",
148 DC_GRADIENT | DC_SMALLCAP);
149 break;
150 case 6:
151 DrawCaptionTest(hWnd, hDc,
152 L"DC_GRADIENT | DC_BUTTONS",
153 DC_GRADIENT | DC_BUTTONS);
154 break;
155 case 7:
156 DrawCaptionTest(hWnd, hDc,
157 L"DC_BUTTONS | DC_SMALLCAP",
158 DC_BUTTONS | DC_SMALLCAP);
159 break;
160 case 8:
161 DrawCaptionTest(hWnd, hDc,
162 L"DC_BUTTONS | DC_SMALLCAP | DC_GRADIENT",
163 DC_BUTTONS | DC_SMALLCAP | DC_GRADIENT);
164 break;
165 }
166
167 EndPaint(hWnd, &Ps);
168
169 return 0;
170 }
171
172 case WM_DESTROY:
173 {
174 PostQuitMessage(0);
175 return 0;
176 }
177 }
178
179 return DefWindowProc(hWnd, msg, wParam, lParam);
180 }
181
182
183 int wmain(int argc, wchar_t**argv)
184 {
185 HWND hWnd;
186 MSG msg;
187 WNDCLASSEX wcx;
188 UINT result;
189 HBRUSH hBr;
190 //HMODULE hLib;
191
192 if(argc<2)
193 {
194 printf("DrawCaption testcode.\n");
195 printf("USAGE: drawcap.exe <testnumber> [useicon]\n\n");
196 printf("Available tests:\n"
197 "1. DrawCaption test\n"
198 "2. DrawCaption test + DC_GRADIENT\n"
199 "3. DrawCaption test + DC_SMALLCAP\n"
200 "4. DrawCaption test + DC_BUTTONS\n"
201 "5. DrawCaption test + DC_GRADIENT | DC_SMALLCAP\n"
202 "6. DrawCaption test + DC_GRADIENT | DC_BUTTONS\n"
203 "7. DrawCaption test + DC_BUTTONS | DC_SMALLCAP\n"
204 "8. DrawCaption test + DC_BUTTONS | DC_SMALLCAP | DC_GRADIENT\n\n");
205 return 0;
206 }
207
208 testnum = _wtoi(argv[1]);
209 if(testnum < 1 || testnum > 8)
210 {
211 printf("Unknown test %d\n", testnum);
212 return 1;
213 }
214
215 hInst = GetModuleHandle(NULL);
216
217 //hLib = LoadLibrary(L"user32");
218 //if(!hLib)
219 //{
220 // printf("Shit! Can't load user32.dll\n");
221 // return 1;
222 //}
223
224 //DrawCaptionTemp = GetProcAddress(hLib, "DrawCaptionTempW");
225 //if(!DrawCaptionTemp)
226 //{
227 // printf("Shit! Can't get DrawCaptionTemp address\n");
228 // return 1;
229 //}
230
231 hBr = CreateSolidBrush(RGB(255, 255, 255));
232 if(!hBr)
233 {
234 printf("Shit! Can't create brush.");
235 return 1;
236 }
237
238 memset(&wcx, 0, sizeof(wcx));
239 wcx.cbSize = sizeof(wcx);
240 wcx.style = CS_HREDRAW | CS_VREDRAW;
241 wcx.lpfnWndProc = (WNDPROC) CaptWndProc;
242 wcx.hInstance = hInst;
243 wcx.hbrBackground = hBr;
244 wcx.lpszClassName = CaptWndClass;
245 if(argc > 2) wcx.hIconSm = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON1SM));
246
247 if(!(result = RegisterClassEx(&wcx)))
248 {
249 printf("Shit! RegisterClassEx failed: %d\n",
250 (int)GetLastError());
251 DeleteObject(hBr);
252 return 1;
253 }
254
255 hWnd = CreateWindowEx(0,
256 CaptWndClass,
257 L"DrawCaption test",
258 WS_OVERLAPPED|WS_THICKFRAME|WS_SYSMENU,
259 CW_USEDEFAULT,
260 CW_USEDEFAULT,
261 600,
262 470,
263 NULL,
264 0,
265 hInst,
266 NULL);
267
268 if(!hWnd)
269 {
270 printf("Shit! Can't create wnd!\n");
271 UnregisterClass(CaptWndClass, hInst);
272 DeleteObject(hBr);
273 return 1;
274 }
275
276
277 ShowWindow(hWnd, SW_SHOW);
278 UpdateWindow(hWnd);
279
280 while(GetMessage(&msg, NULL, 0, 0 ))
281 {
282 TranslateMessage(&msg);
283 DispatchMessage(&msg);
284 }
285
286 DeleteObject(hBr);
287 UnregisterClass(CaptWndClass, hInst);
288 return 0;
289 }