dbghelp: Remove DMT_ entries for .DBG and .PDB files.
[wine.git] / dlls / comctl32 / tests / status.c
blob1851507481f0313ce5d88dc670b2cd0b6365d796
1 /* Unit test suite for status control.
3 * Copyright 2007 Google (Lei Zhang)
4 * Copyright 2007 Alex Arazi
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <windows.h>
22 #include <commctrl.h>
24 #include "wine/test.h"
26 #define SUBCLASS_NAME "MyStatusBar"
28 #define expect(expected,got) expect_(__LINE__, expected, got)
29 static inline void expect_(unsigned line, DWORD expected, DWORD got)
31 ok_(__FILE__, line)(expected == got, "Expected %ld, got %ld\n", expected, got);
34 #define expect_rect(_left,_top,_right,_bottom,got) do { \
35 RECT exp = {abs(got.left - _left), abs(got.top - _top), \
36 abs(got.right - _right), abs(got.bottom - _bottom)}; \
37 ok(exp.left <= 2 && exp.top <= 2 && exp.right <= 2 && exp.bottom <= 2, \
38 "Expected rect (%d,%d)-(%d,%d), got %s\n", _left, _top, _right, _bottom, \
39 wine_dbgstr_rect(&(got))); } while (0)
41 static HINSTANCE hinst;
42 static WNDPROC g_status_wndproc;
43 static RECT g_rcCreated;
44 static HWND g_hMainWnd;
45 static int g_wmsize_count = 0;
46 static INT g_ysize;
47 static INT g_dpisize;
48 static int g_wmdrawitm_ctr;
49 static WNDPROC g_wndproc_saved;
51 static BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
53 static HWND create_status_control(DWORD style, DWORD exstyle)
55 HWND hWndStatus;
57 /* make the control */
58 hWndStatus = CreateWindowExA(exstyle, STATUSCLASSNAMEA, NULL, style,
59 /* placement */
60 0, 0, 300, 20,
61 /* parent, etc */
62 NULL, NULL, hinst, NULL);
63 ok(hWndStatus != NULL, "failed to create status wnd\n");
64 return hWndStatus;
67 static LRESULT WINAPI create_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
69 LRESULT ret;
71 if (msg == WM_CREATE)
73 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
74 ret = CallWindowProcA(g_status_wndproc, hwnd, msg, wParam, lParam);
75 GetWindowRect(hwnd, &g_rcCreated);
76 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&g_rcCreated, 2);
77 ok(cs->x == g_rcCreated.left, "CREATESTRUCT.x modified\n");
78 ok(cs->y == g_rcCreated.top, "CREATESTRUCT.y modified\n");
79 } else if (msg == WM_SIZE)
81 g_wmsize_count++;
82 ret = CallWindowProcA(g_status_wndproc, hwnd, msg, wParam, lParam);
84 else
85 ret = CallWindowProcA(g_status_wndproc, hwnd, msg, wParam, lParam);
87 return ret;
90 static void register_subclass(void)
92 WNDCLASSEXA cls;
94 cls.cbSize = sizeof(WNDCLASSEXA);
95 GetClassInfoExA(NULL, STATUSCLASSNAMEA, &cls);
96 g_status_wndproc = cls.lpfnWndProc;
97 cls.lpfnWndProc = create_test_wndproc;
98 cls.lpszClassName = SUBCLASS_NAME;
99 cls.hInstance = NULL;
100 ok(RegisterClassExA(&cls), "RegisterClassEx failed\n");
103 static void test_create(void)
105 RECT rc;
106 HWND hwnd;
108 ok((hwnd = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP, 0, 0, 100, 100,
109 g_hMainWnd, NULL, NULL, 0)) != NULL, "CreateWindowA failed\n");
110 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
111 GetWindowRect(hwnd, &rc);
112 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
113 expect_rect(0, 0, 100, 100, g_rcCreated);
114 expect(0, rc.left);
115 expect(672, rc.right);
116 expect(226, rc.bottom);
117 /* we don't check rc.top as this may depend on user font settings */
118 DestroyWindow(hwnd);
121 static int CALLBACK check_height_font_enumproc(ENUMLOGFONTEXA *enumlf, NEWTEXTMETRICEXA *ntm, DWORD type, LPARAM lParam)
123 HWND hwndStatus = (HWND)lParam;
124 HDC hdc = GetDC(NULL);
125 static const int sizes[] = { 6, 7, 8, 9, 10, 11, 12, 13, 15, 16,
126 20, 22, 28, 36, 48, 72};
127 DWORD i;
128 INT y;
129 LPSTR facename = (CHAR *)enumlf->elfFullName;
131 /* on win9x, enumlf->elfFullName is only valid for truetype fonts */
132 if (type != TRUETYPE_FONTTYPE)
133 facename = enumlf->elfLogFont.lfFaceName;
135 for (i = 0; i < ARRAY_SIZE(sizes); i++)
137 HFONT hFont;
138 TEXTMETRICA tm;
139 HFONT hCtrlFont;
140 HFONT hOldFont;
141 RECT rcCtrl;
143 enumlf->elfLogFont.lfHeight = sizes[i];
144 hFont = CreateFontIndirectA(&enumlf->elfLogFont);
145 hCtrlFont = (HFONT)SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
146 hOldFont = SelectObject(hdc, hFont);
148 GetClientRect(hwndStatus, &rcCtrl);
149 GetTextMetricsA(hdc, &tm);
150 y = tm.tmHeight + (tm.tmInternalLeading ? tm.tmInternalLeading : 2) + 4;
152 ok( (rcCtrl.bottom == max(y, g_ysize)) || (rcCtrl.bottom == max(y, g_dpisize)),
153 "got %ld (expected %d or %d) for %s #%d\n",
154 rcCtrl.bottom, max(y, g_ysize), max(y, g_dpisize), facename, sizes[i]);
156 SelectObject(hdc, hOldFont);
157 SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hCtrlFont, TRUE);
158 DeleteObject(hFont);
160 ReleaseDC(NULL, hdc);
161 return 1;
164 static int CALLBACK check_height_family_enumproc(ENUMLOGFONTEXA *enumlf, NEWTEXTMETRICEXA *ntm, DWORD type, LPARAM lParam)
166 HDC hdc = GetDC(NULL);
167 enumlf->elfLogFont.lfHeight = 0;
168 EnumFontFamiliesExA(hdc, &enumlf->elfLogFont, (FONTENUMPROCA)check_height_font_enumproc, lParam, 0);
169 ReleaseDC(NULL, hdc);
170 return 1;
173 static void test_height(void)
175 LOGFONTA lf;
176 HFONT hFont, hFontSm;
177 RECT rc1, rc2;
178 HWND hwndStatus = CreateWindowA(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
179 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
180 HDC hdc;
182 GetClientRect(hwndStatus, &rc1);
183 hFont = CreateFontA(32, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
184 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
186 g_wmsize_count = 0;
187 SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
188 if (!g_wmsize_count)
190 skip("Status control not resized in win95, skipping broken tests.\n");
191 return;
193 ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
195 GetClientRect(hwndStatus, &rc2);
196 expect_rect(0, 0, 672, 42, rc2); /* GetTextMetrics returns invalid tmInternalLeading for this font */
198 g_wmsize_count = 0;
199 SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
200 ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
202 GetClientRect(hwndStatus, &rc2);
203 expect_rect(0, 0, 672, 42, rc2);
205 /* minheight < fontsize - no effects*/
206 SendMessageA(hwndStatus, SB_SETMINHEIGHT, 12, 0);
207 SendMessageA(hwndStatus, WM_SIZE, 0, 0);
208 GetClientRect(hwndStatus, &rc2);
209 expect_rect(0, 0, 672, 42, rc2);
211 /* minheight > fontsize - has an effect after WM_SIZE */
212 SendMessageA(hwndStatus, SB_SETMINHEIGHT, 60, 0);
213 GetClientRect(hwndStatus, &rc2);
214 expect_rect(0, 0, 672, 42, rc2);
215 SendMessageA(hwndStatus, WM_SIZE, 0, 0);
216 GetClientRect(hwndStatus, &rc2);
217 expect_rect(0, 0, 672, 62, rc2);
219 /* font changed to smaller than minheight - has an effect */
220 SendMessageA(hwndStatus, SB_SETMINHEIGHT, 30, 0);
221 expect_rect(0, 0, 672, 62, rc2);
222 SendMessageA(hwndStatus, WM_SIZE, 0, 0);
223 GetClientRect(hwndStatus, &rc2);
224 expect_rect(0, 0, 672, 42, rc2);
225 hFontSm = CreateFontA(9, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
226 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
227 SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFontSm, TRUE);
228 GetClientRect(hwndStatus, &rc2);
229 expect_rect(0, 0, 672, 32, rc2);
231 /* test the height formula */
232 ZeroMemory(&lf, sizeof(lf));
233 SendMessageA(hwndStatus, SB_SETMINHEIGHT, 0, 0);
234 hdc = GetDC(NULL);
236 /* used only for some fonts (tahoma as example) */
237 g_ysize = GetSystemMetrics(SM_CYSIZE) + 2;
238 if (g_ysize & 1) g_ysize--; /* The min height is always even */
240 g_dpisize = MulDiv(18, GetDeviceCaps(hdc, LOGPIXELSY), 96) + 2;
241 if (g_dpisize & 1) g_dpisize--; /* The min height is always even */
244 trace("dpi=%d (min height: %d or %d) SM_CYSIZE: %d\n",
245 GetDeviceCaps(hdc, LOGPIXELSY), g_ysize, g_dpisize,
246 GetSystemMetrics(SM_CYSIZE));
248 EnumFontFamiliesExA(hdc, &lf, (FONTENUMPROCA)check_height_family_enumproc, (LPARAM)hwndStatus, 0);
249 ReleaseDC(NULL, hdc);
251 DestroyWindow(hwndStatus);
252 DeleteObject(hFont);
253 DeleteObject(hFontSm);
256 static void test_status_control(void)
258 HWND hWndStatus;
259 int r;
260 int nParts[] = {50, 150, -1};
261 int checkParts[] = {0, 0, 0, 0, 0};
262 int borders[] = {0, 0, 0};
263 RECT rc;
264 CHAR charArray[20];
265 HICON hIcon;
266 char ch;
267 char chstr[10] = "Inval id";
268 COLORREF crColor = RGB(0,0,0);
269 WCHAR wbuf[20];
271 hWndStatus = create_status_control(WS_VISIBLE | SBT_TOOLTIPS, 0);
273 /* Divide into parts and set text */
274 r = SendMessageA(hWndStatus, SB_SETPARTS, 3, (LPARAM)nParts);
275 expect(TRUE,r);
276 r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_POPOUT|0, (LPARAM)"First");
277 expect(TRUE,r);
278 r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_OWNERDRAW|1, (LPARAM)"Second");
279 expect(TRUE,r);
280 r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_NOBORDERS|2, (LPARAM)"Third");
281 expect(TRUE,r);
283 /* Get RECT Information */
284 r = SendMessageA(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
285 expect(TRUE,r);
286 expect(2,rc.top);
287 /* The rc.bottom test is system dependent
288 expect(22,rc.bottom); */
289 expect(0,rc.left);
290 expect(50,rc.right);
291 r = SendMessageA(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
292 expect(FALSE,r);
293 r = SendMessageA(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
294 expect(FALSE,r);
295 /* Get text length and text */
296 r = SendMessageA(hWndStatus, SB_GETTEXTLENGTHA, 0, 0);
297 expect(5,LOWORD(r));
298 expect(SBT_POPOUT,HIWORD(r));
299 r = SendMessageW(hWndStatus, WM_GETTEXTLENGTH, 0, 0);
300 ok(r == 5, "Expected 5, got %d\n", r);
301 r = SendMessageA(hWndStatus, SB_GETTEXTLENGTHA, 1, 0);
302 expect(0,LOWORD(r));
303 expect(SBT_OWNERDRAW,HIWORD(r));
304 r = SendMessageA(hWndStatus, SB_GETTEXTLENGTHA, 2, 0);
305 expect(5,LOWORD(r));
306 expect(SBT_NOBORDERS,HIWORD(r));
307 r = SendMessageA(hWndStatus, SB_GETTEXTA, 2, (LPARAM) charArray);
308 ok(strcmp(charArray,"Third") == 0, "Expected Third, got %s\n", charArray);
309 expect(5,LOWORD(r));
310 expect(SBT_NOBORDERS,HIWORD(r));
312 /* Get parts */
313 r = SendMessageA(hWndStatus, SB_GETPARTS, 3, (LPARAM)checkParts);
314 ok(r == 3, "Expected 3, got %d\n", r);
315 expect(50,checkParts[0]);
316 expect(150,checkParts[1]);
317 expect(-1,checkParts[2]);
318 r = SendMessageA(hWndStatus, SB_GETPARTS, 5, (LPARAM)checkParts);
319 ok(r == 3, "Expected 3, got %d\n", r);
320 expect(50,checkParts[0]);
321 expect(150,checkParts[1]);
322 expect(-1,checkParts[2]);
323 expect(0,checkParts[3]);
324 expect(0,checkParts[4]);
325 /* Get borders */
326 r = SendMessageA(hWndStatus, SB_GETBORDERS, 0, (LPARAM)borders);
327 ok(r == TRUE, "Expected TRUE, got %d\n", r);
328 expect(0,borders[0]);
329 expect(2,borders[1]);
330 expect(2,borders[2]);
332 /* Test resetting text with different characters */
333 r = SendMessageA(hWndStatus, SB_SETPARTS, 4, (LPARAM)nParts);
334 expect(TRUE,r);
335 r = SendMessageA(hWndStatus, SB_SETTEXTA, 0, (LPARAM)"First@Again");
336 expect(TRUE,r);
337 r = SendMessageA(hWndStatus, SB_SETTEXTA, 1, (LPARAM)"Invalid\tChars\\7\7");
338 expect(TRUE,r);
339 r = SendMessageA(hWndStatus, SB_SETTEXTA, 2, (LPARAM)"InvalidChars\\n\n");
340 expect(TRUE,r);
341 r = SendMessageW(hWndStatus, SB_SETTEXTW, 3, (LPARAM)L"Non printable\x80");
342 expect(TRUE,r);
344 /* Get text again */
345 r = SendMessageA(hWndStatus, SB_GETTEXTA, 0, (LPARAM) charArray);
346 ok(strcmp(charArray,"First@Again") == 0, "Expected First@Again, got %s\n", charArray);
347 ok(r == 11, "r = %d\n", r);
349 r = SendMessageA(hWndStatus, SB_GETTEXTA, 1, (LPARAM) charArray);
350 ok(strcmp(charArray,"Invalid\tChars\\7 ") == 0, "Expected Invalid\tChars\\7 , got %s\n", charArray);
351 ok(r == 16, "r = %d\n", r);
353 r = SendMessageA(hWndStatus, SB_GETTEXTA, 2, (LPARAM) charArray);
354 ok(strcmp(charArray,"InvalidChars\\n ") == 0, "Expected InvalidChars\\n , got %s\n", charArray);
355 ok(r == 15, "r = %d\n", r);
357 r = SendMessageW(hWndStatus, SB_GETTEXTW, 3, (LPARAM) wbuf);
358 ok(wcscmp(wbuf, L"Non printable\x80") == 0, "got %s\n", wine_dbgstr_w(wbuf));
359 ok(r == 14, "r = %d\n", r);
361 /* test more nonprintable chars */
362 for(ch = 0x00; ch < 0x7F; ch++) {
363 chstr[5] = ch;
364 r = SendMessageA(hWndStatus, SB_SETTEXTA, 0, (LPARAM)chstr);
365 expect(TRUE,r);
366 r = SendMessageA(hWndStatus, SB_GETTEXTA, 0, (LPARAM)charArray);
367 ok(r == strlen(charArray), "got %d\n", r);
368 /* substitution with single space */
369 if (ch > 0x00 && ch < 0x20 && ch != '\t')
370 chstr[5] = ' ';
371 ok(strcmp(charArray, chstr) == 0, "Expected %s, got %s\n", chstr, charArray);
374 /* Set background color */
375 crColor = SendMessageA(hWndStatus, SB_SETBKCOLOR , 0, RGB(255,0,0));
376 ok(crColor == CLR_DEFAULT ||
377 broken(crColor == RGB(0,0,0)), /* win95 */
378 "Expected 0x%.8lx, got 0x%.8lx\n", CLR_DEFAULT, crColor);
379 crColor = SendMessageA(hWndStatus, SB_SETBKCOLOR , 0, CLR_DEFAULT);
380 ok(crColor == RGB(255,0,0) ||
381 broken(crColor == RGB(0,0,0)), /* win95 */
382 "Expected 0x%.8lx, got 0x%.8lx\n", RGB(255,0,0), crColor);
384 /* Add an icon to the status bar */
385 hIcon = LoadIconA(NULL, (LPCSTR)IDI_QUESTION);
386 r = SendMessageA(hWndStatus, SB_SETICON, 1, 0);
387 ok(r != 0 ||
388 broken(r == 0), /* win95 */
389 "Expected non-zero, got %d\n", r);
390 r = SendMessageA(hWndStatus, SB_SETICON, 1, (LPARAM) hIcon);
391 ok(r != 0 ||
392 broken(r == 0), /* win95 */
393 "Expected non-zero, got %d\n", r);
394 r = SendMessageA(hWndStatus, SB_SETICON, 1, 0);
395 ok(r != 0 ||
396 broken(r == 0), /* win95 */
397 "Expected non-zero, got %d\n", r);
399 /* Set the Unicode format */
400 r = SendMessageA(hWndStatus, SB_SETUNICODEFORMAT, FALSE, 0);
401 expect(FALSE,r);
402 r = SendMessageA(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
403 expect(FALSE,r);
404 r = SendMessageA(hWndStatus, SB_SETUNICODEFORMAT, TRUE, 0);
405 expect(FALSE,r);
406 r = SendMessageA(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
407 ok(r == TRUE ||
408 broken(r == FALSE), /* win95 */
409 "Expected TRUE, got %d\n", r);
411 /* Reset number of parts */
412 r = SendMessageA(hWndStatus, SB_SETPARTS, 2, (LPARAM)nParts);
413 expect(TRUE,r);
414 r = SendMessageA(hWndStatus, SB_GETPARTS, 0, 0);
415 ok(r == 2, "Expected 2, got %d\n", r);
416 r = SendMessageA(hWndStatus, SB_SETPARTS, 0, 0);
417 expect(FALSE,r);
418 r = SendMessageA(hWndStatus, SB_GETPARTS, 0, 0);
419 ok(r == 2, "Expected 2, got %d\n", r);
421 /* Set the minimum height and get rectangle information again */
422 SendMessageA(hWndStatus, SB_SETMINHEIGHT, 50, 0);
423 r = SendMessageA(hWndStatus, WM_SIZE, 0, 0);
424 expect(0,r);
425 r = SendMessageA(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
426 expect(TRUE,r);
427 expect(2,rc.top);
428 /* The rc.bottom test is system dependent
429 expect(22,rc.bottom); */
430 expect(0,rc.left);
431 expect(50,rc.right);
432 r = SendMessageA(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
433 expect(FALSE,r);
434 r = SendMessageA(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
435 expect(FALSE,r);
437 /* Set the ToolTip text */
438 SendMessageA(hWndStatus, SB_SETTIPTEXTA, 0,(LPARAM) "Tooltip Text");
439 lstrcpyA(charArray, "apple");
440 SendMessageA(hWndStatus, SB_GETTIPTEXTA, MAKEWPARAM (0, 20),(LPARAM) charArray);
441 ok(strcmp(charArray,"Tooltip Text") == 0 ||
442 broken(!strcmp(charArray, "apple")), /* win95 */
443 "Expected Tooltip Text, got %s\n", charArray);
445 /* Make simple */
446 SendMessageA(hWndStatus, SB_SIMPLE, TRUE, 0);
447 r = SendMessageA(hWndStatus, SB_ISSIMPLE, 0, 0);
448 ok(r == TRUE ||
449 broken(r == FALSE), /* win95 */
450 "Expected TRUE, got %d\n", r);
452 DestroyWindow(hWndStatus);
455 static LRESULT WINAPI ownerdraw_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
457 LRESULT ret;
458 if (msg == WM_DRAWITEM)
459 g_wmdrawitm_ctr++;
460 ret = CallWindowProcA(g_wndproc_saved, hwnd, msg, wParam, lParam);
461 return ret;
464 static void test_status_ownerdraw(void)
466 HWND hWndStatus;
467 int r;
468 const char* statustext = "STATUS TEXT";
469 LONG oldstyle;
471 /* subclass the main window and make sure it is visible */
472 g_wndproc_saved = (WNDPROC) SetWindowLongPtrA( g_hMainWnd, GWLP_WNDPROC,
473 (LONG_PTR)ownerdraw_test_wndproc );
474 ok( g_wndproc_saved != 0, "failed to set the WndProc\n");
475 SetWindowPos( g_hMainWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
476 oldstyle = GetWindowLongA( g_hMainWnd, GWL_STYLE);
477 SetWindowLongA( g_hMainWnd, GWL_STYLE, oldstyle | WS_VISIBLE);
478 /* create a status child window */
479 ok((hWndStatus = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE, 0, 0, 100, 100,
480 g_hMainWnd, NULL, NULL, 0)) != NULL, "CreateWindowA failed\n");
481 /* set text */
482 g_wmdrawitm_ctr = 0;
483 r = SendMessageA(hWndStatus, SB_SETTEXTA, 0, (LPARAM)statustext);
484 ok( r == TRUE, "Sendmessage returned %d, expected 1\n", r);
485 ok( 0 == g_wmdrawitm_ctr, "got %d drawitem messages expected none\n", g_wmdrawitm_ctr);
486 /* set same text, with ownerdraw flag */
487 g_wmdrawitm_ctr = 0;
488 r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_OWNERDRAW, (LPARAM)statustext);
489 ok( r == TRUE, "Sendmessage returned %d, expected 1\n", r);
490 ok( 1 == g_wmdrawitm_ctr, "got %d drawitem messages expected 1\n", g_wmdrawitm_ctr);
491 /* and again */
492 g_wmdrawitm_ctr = 0;
493 r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_OWNERDRAW, (LPARAM)statustext);
494 ok( r == TRUE, "Sendmessage returned %d, expected 1\n", r);
495 ok( 1 == g_wmdrawitm_ctr, "got %d drawitem messages expected 1\n", g_wmdrawitm_ctr);
496 /* clean up */
497 DestroyWindow(hWndStatus);
498 SetWindowLongA( g_hMainWnd, GWL_STYLE, oldstyle);
499 SetWindowLongPtrA( g_hMainWnd, GWLP_WNDPROC, (LONG_PTR)g_wndproc_saved );
502 static void test_gettext(void)
504 HWND hwndStatus = CreateWindowA(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
505 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
506 char buf[5];
507 int r;
509 r = SendMessageA(hwndStatus, SB_SETTEXTA, 0, (LPARAM)"Text");
510 expect(TRUE, r);
511 r = SendMessageA(hwndStatus, WM_GETTEXTLENGTH, 0, 0);
512 expect(4, r);
513 /* A size of 0 returns the length of the text */
514 r = SendMessageA(hwndStatus, WM_GETTEXT, 0, 0);
515 ok( r == 4 || broken(r == 2) /* win8 */, "Expected 4 got %d\n", r );
516 /* A size of 1 only stores the NULL terminator */
517 buf[0] = 0xa;
518 r = SendMessageA(hwndStatus, WM_GETTEXT, 1, (LPARAM)buf);
519 ok( r == 0 || broken(r == 4), "Expected 0 got %d\n", r );
520 if (!r) ok(!buf[0], "expected empty buffer\n");
521 /* A size of 2 returns a length 1 */
522 r = SendMessageA(hwndStatus, WM_GETTEXT, 2, (LPARAM)buf);
523 ok( r == 1 || broken(r == 4), "Expected 1 got %d\n", r );
524 r = SendMessageA(hwndStatus, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
525 expect(4, r);
526 ok(!strcmp(buf, "Text"), "expected Text, got %s\n", buf);
527 DestroyWindow(hwndStatus);
530 /* Notify events to parent */
531 static BOOL g_got_dblclk;
532 static BOOL g_got_click;
533 static BOOL g_got_rdblclk;
534 static BOOL g_got_rclick;
536 /* Messages to parent */
537 static BOOL g_got_contextmenu;
539 static LRESULT WINAPI test_notify_parent_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
541 switch(msg)
543 case WM_NOTIFY:
545 NMHDR *hdr = ((LPNMHDR)lParam);
546 switch(hdr->code)
548 case NM_DBLCLK: g_got_dblclk = TRUE; break;
549 case NM_CLICK: g_got_click = TRUE; break;
550 case NM_RDBLCLK: g_got_rdblclk = TRUE; break;
551 case NM_RCLICK: g_got_rclick = TRUE; break;
554 /* Return zero to indicate default processing */
555 return 0;
558 case WM_CONTEXTMENU: g_got_contextmenu = TRUE; return 0;
560 default:
561 return( DefWindowProcA(hwnd, msg, wParam, lParam));
564 return 0;
567 /* Test that WM_NOTIFY messages from the status control works correctly */
568 static void test_notify(void)
570 HWND hwndParent;
571 HWND hwndStatus;
572 ATOM atom;
573 WNDCLASSA wclass = {0};
574 wclass.lpszClassName = "TestNotifyParentClass";
575 wclass.lpfnWndProc = test_notify_parent_proc;
576 atom = RegisterClassA(&wclass);
577 ok(atom, "RegisterClass failed\n");
579 /* create parent */
580 hwndParent = CreateWindowA(wclass.lpszClassName, "parent", WS_OVERLAPPEDWINDOW,
581 CW_USEDEFAULT, 0, 300, 20, NULL, NULL, NULL, NULL);
582 ok(hwndParent != NULL, "Parent creation failed!\n");
584 /* create status bar */
585 hwndStatus = CreateWindowA(STATUSCLASSNAMEA, NULL, WS_VISIBLE | WS_CHILD,
586 0, 0, 300, 20, hwndParent, NULL, NULL, NULL);
587 ok(hwndStatus != NULL, "Status creation failed!\n");
589 /* Send various mouse event, and check that we get them */
590 g_got_dblclk = FALSE;
591 SendMessageA(hwndStatus, WM_LBUTTONDBLCLK, 0, 0);
592 ok(g_got_dblclk, "WM_LBUTTONDBLCLK was not processed correctly!\n");
593 g_got_rdblclk = FALSE;
594 SendMessageA(hwndStatus, WM_RBUTTONDBLCLK, 0, 0);
595 ok(g_got_rdblclk, "WM_RBUTTONDBLCLK was not processed correctly!\n");
596 g_got_click = FALSE;
597 SendMessageA(hwndStatus, WM_LBUTTONUP, 0, 0);
598 ok(g_got_click, "WM_LBUTTONUP was not processed correctly!\n");
600 /* For R-UP, check that we also get the context menu from the default processing */
601 g_got_contextmenu = FALSE;
602 g_got_rclick = FALSE;
603 SendMessageA(hwndStatus, WM_RBUTTONUP, 0, 0);
604 ok(g_got_rclick, "WM_RBUTTONUP was not processed correctly!\n");
605 ok(g_got_contextmenu, "WM_RBUTTONUP did not activate the context menu!\n");
608 static void test_sizegrip(void)
610 HWND hwndStatus;
611 LONG style;
612 RECT rc, rcClient;
613 POINT pt;
614 int width, r;
616 hwndStatus = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP,
617 0, 0, 100, 100, g_hMainWnd, NULL, NULL, NULL);
619 style = GetWindowLongPtrA(g_hMainWnd, GWL_STYLE);
620 width = GetSystemMetrics(SM_CXVSCROLL);
622 GetClientRect(hwndStatus, &rcClient);
624 pt.x = rcClient.right;
625 pt.y = rcClient.top;
626 ClientToScreen(hwndStatus, &pt);
627 rc.left = pt.x - width;
628 rc.right = pt.x;
629 rc.top = pt.y;
631 pt.y = rcClient.bottom;
632 ClientToScreen(hwndStatus, &pt);
633 rc.bottom = pt.y;
635 /* check bounds when not maximized */
636 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top));
637 expect(HTBOTTOMRIGHT, r);
638 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left - 1, rc.top));
639 expect(HTCLIENT, r);
640 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top - 1));
641 expect(HTBOTTOMRIGHT, r);
642 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom));
643 expect(HTBOTTOMRIGHT, r);
644 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right + 1, rc.bottom));
645 expect(HTBOTTOMRIGHT, r);
646 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom + 1));
647 expect(HTBOTTOMRIGHT, r);
648 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right - 1, rc.bottom - 1));
649 expect(HTBOTTOMRIGHT, r);
651 /* not maximized and right-to-left */
652 SetWindowLongA(hwndStatus, GWL_EXSTYLE, WS_EX_LAYOUTRTL);
654 pt.x = rcClient.right;
655 ClientToScreen(hwndStatus, &pt);
656 rc.left = pt.x + width;
657 rc.right = pt.x;
659 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top));
660 expect(HTBOTTOMLEFT, r);
661 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left + 1, rc.top));
662 expect(HTCLIENT, r);
663 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top - 1));
664 expect(HTBOTTOMLEFT, r);
665 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom));
666 expect(HTBOTTOMLEFT, r);
667 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right - 1, rc.bottom));
668 expect(HTBOTTOMLEFT, r);
669 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom + 1));
670 expect(HTBOTTOMLEFT, r);
671 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right + 1, rc.bottom - 1));
672 expect(HTBOTTOMLEFT, r);
674 /* maximize with left-to-right */
675 SetWindowLongA(g_hMainWnd, GWL_STYLE, style|WS_MAXIMIZE);
676 SetWindowLongA(hwndStatus, GWL_EXSTYLE, 0);
678 GetClientRect(hwndStatus, &rcClient);
680 pt.x = rcClient.right;
681 pt.y = rcClient.top;
682 ClientToScreen(hwndStatus, &pt);
683 rc.left = pt.x - width;
684 rc.right = pt.x;
685 rc.top = pt.y;
687 pt.y = rcClient.bottom;
688 ClientToScreen(hwndStatus, &pt);
689 rc.bottom = pt.y;
691 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top));
692 expect(HTCLIENT, r);
693 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left - 1, rc.top));
694 expect(HTCLIENT, r);
695 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top - 1));
696 expect(HTNOWHERE, r);
697 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom));
698 expect(HTNOWHERE, r);
699 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right + 1, rc.bottom));
700 expect(HTNOWHERE, r);
701 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom + 1));
702 expect(HTNOWHERE, r);
703 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right - 1, rc.bottom - 1));
704 expect(HTCLIENT, r);
706 /* maximized with right-to-left */
707 SetWindowLongA(hwndStatus, GWL_EXSTYLE, WS_EX_LAYOUTRTL);
709 pt.x = rcClient.right;
710 ClientToScreen(hwndStatus, &pt);
711 rc.left = pt.x + width;
712 rc.right = pt.x;
714 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top));
715 expect(HTCLIENT, r);
716 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left + 1, rc.top));
717 expect(HTCLIENT, r);
718 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top - 1));
719 expect(HTNOWHERE, r);
720 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom));
721 expect(HTNOWHERE, r);
722 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right - 1, rc.bottom));
723 expect(HTNOWHERE, r);
724 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom + 1));
725 expect(HTNOWHERE, r);
726 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right + 1, rc.bottom - 1));
727 expect(HTCLIENT, r);
729 SetWindowLongA(g_hMainWnd, GWL_STYLE, style);
730 DestroyWindow(hwndStatus);
733 static void init_functions(void)
735 HMODULE hComCtl32 = LoadLibraryA("comctl32.dll");
737 #define X(f) p##f = (void*)GetProcAddress(hComCtl32, #f);
738 X(InitCommonControlsEx);
739 #undef X
742 START_TEST(status)
744 INITCOMMONCONTROLSEX iccex;
746 init_functions();
748 hinst = GetModuleHandleA(NULL);
750 iccex.dwSize = sizeof(iccex);
751 iccex.dwICC = ICC_BAR_CLASSES;
752 pInitCommonControlsEx(&iccex);
754 g_hMainWnd = CreateWindowExA(0, WC_STATICA, "", WS_OVERLAPPEDWINDOW,
755 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
756 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
757 NULL, NULL, GetModuleHandleA(NULL), 0);
759 register_subclass();
761 test_status_control();
762 test_create();
763 test_height();
764 test_status_ownerdraw();
765 test_gettext();
766 test_notify();
767 test_sizegrip();