1 /* Unit test suite for status control.
2  *
3  * Copyright 2007 Google (Lei Zhang)
4  * Copyright 2007 Alex Arazi
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include "precomp.h"
22 
23 #define SUBCLASS_NAME "MyStatusBar"
24 
25 #define expect(expected,got) ok (expected == got,"Expected %d, got %d\n",expected,got)
26 #define expect_rect(_left,_top,_right,_bottom,got) do { \
27         RECT exp = {abs(got.left - _left), abs(got.top - _top), \
28                     abs(got.right - _right), abs(got.bottom - _bottom)}; \
29         ok(exp.left <= 2 && exp.top <= 2 && exp.right <= 2 && exp.bottom <= 2, \
30            "Expected rect (%d,%d)-(%d,%d), got %s\n", _left, _top, _right, _bottom, \
31            wine_dbgstr_rect(&(got))); } while (0)
32 
33 static HINSTANCE hinst;
34 static WNDPROC g_status_wndproc;
35 static RECT g_rcCreated;
36 static HWND g_hMainWnd;
37 static int g_wmsize_count = 0;
38 static INT g_ysize;
39 static INT g_dpisize;
40 static int g_wmdrawitm_ctr;
41 static WNDPROC g_wndproc_saved;
42 
43 static HWND create_status_control(DWORD style, DWORD exstyle)
44 {
45     HWND hWndStatus;
46 
47     /* make the control */
48     hWndStatus = CreateWindowExA(exstyle, STATUSCLASSNAMEA, NULL, style,
49         /* placement */
50         0, 0, 300, 20,
51         /* parent, etc */
52         NULL, NULL, hinst, NULL);
53     ok(hWndStatus != NULL, "failed to create status wnd\n");
54     return hWndStatus;
55 }
56 
57 static LRESULT WINAPI create_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
58 {
59     LRESULT ret;
60 
61     if (msg == WM_CREATE)
62     {
63         CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
64         ret = CallWindowProcA(g_status_wndproc, hwnd, msg, wParam, lParam);
65         GetWindowRect(hwnd, &g_rcCreated);
66         MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&g_rcCreated, 2);
67         ok(cs->x == g_rcCreated.left, "CREATESTRUCT.x modified\n");
68         ok(cs->y == g_rcCreated.top, "CREATESTRUCT.y modified\n");
69     } else if (msg == WM_SIZE)
70     {
71         g_wmsize_count++;
72         ret = CallWindowProcA(g_status_wndproc, hwnd, msg, wParam, lParam);
73     }
74     else
75         ret = CallWindowProcA(g_status_wndproc, hwnd, msg, wParam, lParam);
76 
77     return ret;
78 }
79 
80 static void register_subclass(void)
81 {
82     WNDCLASSEXA cls;
83 
84     cls.cbSize = sizeof(WNDCLASSEXA);
85     GetClassInfoExA(NULL, STATUSCLASSNAMEA, &cls);
86     g_status_wndproc = cls.lpfnWndProc;
87     cls.lpfnWndProc = create_test_wndproc;
88     cls.lpszClassName = SUBCLASS_NAME;
89     cls.hInstance = NULL;
90     ok(RegisterClassExA(&cls), "RegisterClassEx failed\n");
91 }
92 
93 static void test_create(void)
94 {
95     RECT rc;
96     HWND hwnd;
97 
98     ok((hwnd = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP, 0, 0, 100, 100,
99         g_hMainWnd, NULL, NULL, 0)) != NULL, "CreateWindowA failed\n");
100     MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
101     GetWindowRect(hwnd, &rc);
102     MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
103     expect_rect(0, 0, 100, 100, g_rcCreated);
104     expect(0, rc.left);
105     expect(672, rc.right);
106     expect(226, rc.bottom);
107     /* we don't check rc.top as this may depend on user font settings */
108     DestroyWindow(hwnd);
109 }
110 
111 static int CALLBACK check_height_font_enumproc(ENUMLOGFONTEXA *enumlf, NEWTEXTMETRICEXA *ntm, DWORD type, LPARAM lParam)
112 {
113     HWND hwndStatus = (HWND)lParam;
114     HDC hdc = GetDC(NULL);
115     static const int sizes[] = { 6,  7,  8,  9, 10, 11, 12, 13, 15, 16,
116                                 20, 22, 28, 36, 48, 72};
117     DWORD i;
118     INT y;
119     LPSTR facename = (CHAR *)enumlf->elfFullName;
120 
121     /* on win9x, enumlf->elfFullName is only valid for truetype fonts */
122     if (type != TRUETYPE_FONTTYPE)
123         facename = enumlf->elfLogFont.lfFaceName;
124 
125     for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
126     {
127         HFONT hFont;
128         TEXTMETRICA tm;
129         HFONT hCtrlFont;
130         HFONT hOldFont;
131         RECT rcCtrl;
132 
133         enumlf->elfLogFont.lfHeight = sizes[i];
134         hFont = CreateFontIndirectA(&enumlf->elfLogFont);
135         hCtrlFont = (HFONT)SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
136         hOldFont = SelectObject(hdc, hFont);
137 
138         GetClientRect(hwndStatus, &rcCtrl);
139         GetTextMetricsA(hdc, &tm);
140         y = tm.tmHeight + (tm.tmInternalLeading ? tm.tmInternalLeading : 2) + 4;
141 
142         ok( (rcCtrl.bottom == max(y, g_ysize)) || (rcCtrl.bottom == max(y, g_dpisize)),
143             "got %d (expected %d or %d) for %s #%d\n",
144             rcCtrl.bottom, max(y, g_ysize), max(y, g_dpisize), facename, sizes[i]);
145 
146         SelectObject(hdc, hOldFont);
147         SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hCtrlFont, TRUE);
148         DeleteObject(hFont);
149     }
150     ReleaseDC(NULL, hdc);
151     return 1;
152 }
153 
154 static int CALLBACK check_height_family_enumproc(ENUMLOGFONTEXA *enumlf, NEWTEXTMETRICEXA *ntm, DWORD type, LPARAM lParam)
155 {
156     HDC hdc = GetDC(NULL);
157     enumlf->elfLogFont.lfHeight = 0;
158     EnumFontFamiliesExA(hdc, &enumlf->elfLogFont, (FONTENUMPROCA)check_height_font_enumproc, lParam, 0);
159     ReleaseDC(NULL, hdc);
160     return 1;
161 }
162 
163 static void test_height(void)
164 {
165     LOGFONTA lf;
166     HFONT hFont, hFontSm;
167     RECT rc1, rc2;
168     HWND hwndStatus = CreateWindowA(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
169         0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
170     HDC hdc;
171 
172     GetClientRect(hwndStatus, &rc1);
173     hFont = CreateFontA(32, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
174         OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
175 
176     g_wmsize_count = 0;
177     SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
178     if (!g_wmsize_count)
179     {
180         skip("Status control not resized in win95, skipping broken tests.\n");
181         return;
182     }
183     ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
184 
185     GetClientRect(hwndStatus, &rc2);
186     expect_rect(0, 0, 672, 42, rc2); /* GetTextMetrics returns invalid tmInternalLeading for this font */
187 
188     g_wmsize_count = 0;
189     SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
190     ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
191 
192     GetClientRect(hwndStatus, &rc2);
193     expect_rect(0, 0, 672, 42, rc2);
194 
195     /* minheight < fontsize - no effects*/
196     SendMessageA(hwndStatus, SB_SETMINHEIGHT, 12, 0);
197     SendMessageA(hwndStatus, WM_SIZE, 0, 0);
198     GetClientRect(hwndStatus, &rc2);
199     expect_rect(0, 0, 672, 42, rc2);
200 
201     /* minheight > fontsize - has an effect after WM_SIZE */
202     SendMessageA(hwndStatus, SB_SETMINHEIGHT, 60, 0);
203     GetClientRect(hwndStatus, &rc2);
204     expect_rect(0, 0, 672, 42, rc2);
205     SendMessageA(hwndStatus, WM_SIZE, 0, 0);
206     GetClientRect(hwndStatus, &rc2);
207     expect_rect(0, 0, 672, 62, rc2);
208 
209     /* font changed to smaller than minheight - has an effect */
210     SendMessageA(hwndStatus, SB_SETMINHEIGHT, 30, 0);
211     expect_rect(0, 0, 672, 62, rc2);
212     SendMessageA(hwndStatus, WM_SIZE, 0, 0);
213     GetClientRect(hwndStatus, &rc2);
214     expect_rect(0, 0, 672, 42, rc2);
215     hFontSm = CreateFontA(9, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
216         OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
217     SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFontSm, TRUE);
218     GetClientRect(hwndStatus, &rc2);
219     expect_rect(0, 0, 672, 32, rc2);
220 
221     /* test the height formula */
222     ZeroMemory(&lf, sizeof(lf));
223     SendMessageA(hwndStatus, SB_SETMINHEIGHT, 0, 0);
224     hdc = GetDC(NULL);
225 
226     /* used only for some fonts (tahoma as example) */
227     g_ysize = GetSystemMetrics(SM_CYSIZE) + 2;
228     if (g_ysize & 1) g_ysize--;     /* The min height is always even */
229 
230     g_dpisize = MulDiv(18, GetDeviceCaps(hdc, LOGPIXELSY), 96) + 2;
231     if (g_dpisize & 1) g_dpisize--; /* The min height is always even */
232 
233 
234     trace("dpi=%d (min height: %d or %d) SM_CYSIZE: %d\n",
235             GetDeviceCaps(hdc, LOGPIXELSY), g_ysize, g_dpisize,
236             GetSystemMetrics(SM_CYSIZE));
237 
238     EnumFontFamiliesExA(hdc, &lf, (FONTENUMPROCA)check_height_family_enumproc, (LPARAM)hwndStatus, 0);
239     ReleaseDC(NULL, hdc);
240 
241     DestroyWindow(hwndStatus);
242     DeleteObject(hFont);
243     DeleteObject(hFontSm);
244 }
245 
246 static void test_status_control(void)
247 {
248     HWND hWndStatus;
249     int r;
250     int nParts[] = {50, 150, -1};
251     int checkParts[] = {0, 0, 0};
252     int borders[] = {0, 0, 0};
253     RECT rc;
254     CHAR charArray[20];
255     HICON hIcon;
256     char ch;
257     char chstr[10] = "Inval id";
258     COLORREF crColor = RGB(0,0,0);
259 
260     hWndStatus = create_status_control(WS_VISIBLE | SBT_TOOLTIPS, 0);
261 
262     /* Divide into parts and set text */
263     r = SendMessageA(hWndStatus, SB_SETPARTS, 3, (LPARAM)nParts);
264     expect(TRUE,r);
265     r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_POPOUT|0,    (LPARAM)"First");
266     expect(TRUE,r);
267     r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_OWNERDRAW|1, (LPARAM)"Second");
268     expect(TRUE,r);
269     r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_NOBORDERS|2, (LPARAM)"Third");
270     expect(TRUE,r);
271 
272     /* Get RECT Information */
273     r = SendMessageA(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
274     expect(TRUE,r);
275     expect(2,rc.top);
276     /* The rc.bottom test is system dependent
277     expect(22,rc.bottom); */
278     expect(0,rc.left);
279     expect(50,rc.right);
280     r = SendMessageA(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
281     expect(FALSE,r);
282     r = SendMessageA(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
283     expect(FALSE,r);
284     /* Get text length and text */
285     r = SendMessageA(hWndStatus, SB_GETTEXTLENGTHA, 0, 0);
286     expect(5,LOWORD(r));
287     expect(SBT_POPOUT,HIWORD(r));
288     r = SendMessageW(hWndStatus, WM_GETTEXTLENGTH, 0, 0);
289     ok(r == 5, "Expected 5, got %d\n", r);
290     r = SendMessageA(hWndStatus, SB_GETTEXTLENGTHA, 1, 0);
291     expect(0,LOWORD(r));
292     expect(SBT_OWNERDRAW,HIWORD(r));
293     r = SendMessageA(hWndStatus, SB_GETTEXTLENGTHA, 2, 0);
294     expect(5,LOWORD(r));
295     expect(SBT_NOBORDERS,HIWORD(r));
296     r = SendMessageA(hWndStatus, SB_GETTEXTA, 2, (LPARAM) charArray);
297     ok(strcmp(charArray,"Third") == 0, "Expected Third, got %s\n", charArray);
298     expect(5,LOWORD(r));
299     expect(SBT_NOBORDERS,HIWORD(r));
300 
301     /* Get parts and borders */
302     r = SendMessageA(hWndStatus, SB_GETPARTS, 3, (LPARAM)checkParts);
303     ok(r == 3, "Expected 3, got %d\n", r);
304     expect(50,checkParts[0]);
305     expect(150,checkParts[1]);
306     expect(-1,checkParts[2]);
307     r = SendMessageA(hWndStatus, SB_GETBORDERS, 0, (LPARAM)borders);
308     ok(r == TRUE, "Expected TRUE, got %d\n", r);
309     expect(0,borders[0]);
310     expect(2,borders[1]);
311     expect(2,borders[2]);
312 
313     /* Test resetting text with different characters */
314     r = SendMessageA(hWndStatus, SB_SETTEXTA, 0, (LPARAM)"First@Again");
315     expect(TRUE,r);
316     r = SendMessageA(hWndStatus, SB_SETTEXTA, 1, (LPARAM)"Invalid\tChars\\7\7");
317         expect(TRUE,r);
318     r = SendMessageA(hWndStatus, SB_SETTEXTA, 2, (LPARAM)"InvalidChars\\n\n");
319         expect(TRUE,r);
320 
321     /* Get text again */
322     r = SendMessageA(hWndStatus, SB_GETTEXTA, 0, (LPARAM) charArray);
323     ok(strcmp(charArray,"First@Again") == 0, "Expected First@Again, got %s\n", charArray);
324     expect(11,LOWORD(r));
325     expect(0,HIWORD(r));
326     r = SendMessageA(hWndStatus, SB_GETTEXTA, 1, (LPARAM) charArray);
327     ok(strcmp(charArray,"Invalid\tChars\\7 ") == 0, "Expected Invalid\tChars\\7 , got %s\n", charArray);
328 
329     expect(16,LOWORD(r));
330     expect(0,HIWORD(r));
331     r = SendMessageA(hWndStatus, SB_GETTEXTA, 2, (LPARAM) charArray);
332     ok(strcmp(charArray,"InvalidChars\\n ") == 0, "Expected InvalidChars\\n , got %s\n", charArray);
333 
334     expect(15,LOWORD(r));
335     expect(0,HIWORD(r));
336 
337     /* test more nonprintable chars */
338     for(ch = 0x00; ch < 0x7F; ch++) {
339         chstr[5] = ch;
340         r = SendMessageA(hWndStatus, SB_SETTEXTA, 0, (LPARAM)chstr);
341         expect(TRUE,r);
342         r = SendMessageA(hWndStatus, SB_GETTEXTA, 0, (LPARAM)charArray);
343         ok(r == strlen(charArray), "got %d\n", r);
344         /* substitution with single space */
345         if (ch > 0x00 && ch < 0x20 && ch != '\t')
346             chstr[5] = ' ';
347         ok(strcmp(charArray, chstr) == 0, "Expected %s, got %s\n", chstr, charArray);
348     }
349 
350     /* Set background color */
351     crColor = SendMessageA(hWndStatus, SB_SETBKCOLOR , 0, RGB(255,0,0));
352     ok(crColor == CLR_DEFAULT ||
353        broken(crColor == RGB(0,0,0)), /* win95 */
354        "Expected 0x%.8x, got 0x%.8x\n", CLR_DEFAULT, crColor);
355     crColor = SendMessageA(hWndStatus, SB_SETBKCOLOR , 0, CLR_DEFAULT);
356     ok(crColor == RGB(255,0,0) ||
357        broken(crColor == RGB(0,0,0)), /* win95 */
358        "Expected 0x%.8x, got 0x%.8x\n", RGB(255,0,0), crColor);
359 
360     /* Add an icon to the status bar */
361     hIcon = LoadIconA(NULL, (LPCSTR)IDI_QUESTION);
362     r = SendMessageA(hWndStatus, SB_SETICON, 1, 0);
363     ok(r != 0 ||
364        broken(r == 0), /* win95 */
365        "Expected non-zero, got %d\n", r);
366     r = SendMessageA(hWndStatus, SB_SETICON, 1, (LPARAM) hIcon);
367     ok(r != 0 ||
368        broken(r == 0), /* win95 */
369        "Expected non-zero, got %d\n", r);
370     r = SendMessageA(hWndStatus, SB_SETICON, 1, 0);
371     ok(r != 0 ||
372        broken(r == 0), /* win95 */
373        "Expected non-zero, got %d\n", r);
374 
375     /* Set the Unicode format */
376     r = SendMessageA(hWndStatus, SB_SETUNICODEFORMAT, FALSE, 0);
377     expect(FALSE,r);
378     r = SendMessageA(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
379     expect(FALSE,r);
380     r = SendMessageA(hWndStatus, SB_SETUNICODEFORMAT, TRUE, 0);
381     expect(FALSE,r);
382     r = SendMessageA(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
383     ok(r == TRUE ||
384        broken(r == FALSE), /* win95 */
385        "Expected TRUE, got %d\n", r);
386 
387     /* Reset number of parts */
388     r = SendMessageA(hWndStatus, SB_SETPARTS, 2, (LPARAM)nParts);
389     expect(TRUE,r);
390     r = SendMessageA(hWndStatus, SB_GETPARTS, 0, 0);
391     ok(r == 2, "Expected 2, got %d\n", r);
392     r = SendMessageA(hWndStatus, SB_SETPARTS, 0, 0);
393     expect(FALSE,r);
394     r = SendMessageA(hWndStatus, SB_GETPARTS, 0, 0);
395     ok(r == 2, "Expected 2, got %d\n", r);
396 
397     /* Set the minimum height and get rectangle information again */
398     SendMessageA(hWndStatus, SB_SETMINHEIGHT, 50, 0);
399     r = SendMessageA(hWndStatus, WM_SIZE, 0, 0);
400     expect(0,r);
401     r = SendMessageA(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
402     expect(TRUE,r);
403     expect(2,rc.top);
404     /* The rc.bottom test is system dependent
405     expect(22,rc.bottom); */
406     expect(0,rc.left);
407     expect(50,rc.right);
408     r = SendMessageA(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
409     expect(FALSE,r);
410     r = SendMessageA(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
411     expect(FALSE,r);
412 
413     /* Set the ToolTip text */
414     SendMessageA(hWndStatus, SB_SETTIPTEXTA, 0,(LPARAM) "Tooltip Text");
415     lstrcpyA(charArray, "apple");
416     SendMessageA(hWndStatus, SB_GETTIPTEXTA, MAKEWPARAM (0, 20),(LPARAM) charArray);
417     ok(strcmp(charArray,"Tooltip Text") == 0 ||
418         broken(!strcmp(charArray, "apple")), /* win95 */
419         "Expected Tooltip Text, got %s\n", charArray);
420 
421     /* Make simple */
422     SendMessageA(hWndStatus, SB_SIMPLE, TRUE, 0);
423     r = SendMessageA(hWndStatus, SB_ISSIMPLE, 0, 0);
424     ok(r == TRUE ||
425        broken(r == FALSE), /* win95 */
426        "Expected TRUE, got %d\n", r);
427 
428     DestroyWindow(hWndStatus);
429 }
430 
431 static LRESULT WINAPI ownerdraw_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
432 {
433     LRESULT ret;
434     if (msg == WM_DRAWITEM)
435         g_wmdrawitm_ctr++;
436     ret = CallWindowProcA(g_wndproc_saved, hwnd, msg, wParam, lParam);
437     return ret;
438 }
439 
440 static void test_status_ownerdraw(void)
441 {
442     HWND hWndStatus;
443     int r;
444     const char* statustext = "STATUS TEXT";
445     LONG oldstyle;
446 
447     /* subclass the main window and make sure it is visible */
448     g_wndproc_saved = (WNDPROC) SetWindowLongPtrA( g_hMainWnd, GWLP_WNDPROC,
449                                                   (LONG_PTR)ownerdraw_test_wndproc );
450     ok( g_wndproc_saved != 0, "failed to set the WndProc\n");
451     SetWindowPos( g_hMainWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
452     oldstyle = GetWindowLongA( g_hMainWnd, GWL_STYLE);
453     SetWindowLongA( g_hMainWnd, GWL_STYLE, oldstyle | WS_VISIBLE);
454     /* create a status child window */
455     ok((hWndStatus = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE, 0, 0, 100, 100,
456                     g_hMainWnd, NULL, NULL, 0)) != NULL, "CreateWindowA failed\n");
457     /* set text */
458     g_wmdrawitm_ctr = 0;
459     r = SendMessageA(hWndStatus, SB_SETTEXTA, 0, (LPARAM)statustext);
460     ok( r == TRUE, "Sendmessage returned %d, expected 1\n", r);
461     ok( 0 == g_wmdrawitm_ctr, "got %d drawitem messages expected none\n", g_wmdrawitm_ctr);
462     /* set same text, with ownerdraw flag */
463     g_wmdrawitm_ctr = 0;
464     r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_OWNERDRAW, (LPARAM)statustext);
465     ok( r == TRUE, "Sendmessage returned %d, expected 1\n", r);
466     ok( 1 == g_wmdrawitm_ctr, "got %d drawitem messages expected 1\n", g_wmdrawitm_ctr);
467     /* and again */
468     g_wmdrawitm_ctr = 0;
469     r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_OWNERDRAW, (LPARAM)statustext);
470     ok( r == TRUE, "Sendmessage returned %d, expected 1\n", r);
471     ok( 1 == g_wmdrawitm_ctr, "got %d drawitem messages expected 1\n", g_wmdrawitm_ctr);
472     /* clean up */
473     DestroyWindow(hWndStatus);
474     SetWindowLongA( g_hMainWnd, GWL_STYLE, oldstyle);
475     SetWindowLongPtrA( g_hMainWnd, GWLP_WNDPROC, (LONG_PTR)g_wndproc_saved );
476 }
477 
478 static void test_gettext(void)
479 {
480     HWND hwndStatus = CreateWindowA(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
481         0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
482     char buf[5];
483     int r;
484 
485     r = SendMessageA(hwndStatus, SB_SETTEXTA, 0, (LPARAM)"Text");
486     expect(TRUE, r);
487     r = SendMessageA(hwndStatus, WM_GETTEXTLENGTH, 0, 0);
488     expect(4, r);
489     /* A size of 0 returns the length of the text */
490     r = SendMessageA(hwndStatus, WM_GETTEXT, 0, 0);
491     ok( r == 4 || broken(r == 2) /* win8 */, "Expected 4 got %d\n", r );
492     /* A size of 1 only stores the NULL terminator */
493     buf[0] = 0xa;
494     r = SendMessageA(hwndStatus, WM_GETTEXT, 1, (LPARAM)buf);
495     ok( r == 0 || broken(r == 4), "Expected 0 got %d\n", r );
496     if (!r) ok(!buf[0], "expected empty buffer\n");
497     /* A size of 2 returns a length 1 */
498     r = SendMessageA(hwndStatus, WM_GETTEXT, 2, (LPARAM)buf);
499     ok( r == 1 || broken(r == 4), "Expected 1 got %d\n", r );
500     r = SendMessageA(hwndStatus, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
501     expect(4, r);
502     ok(!strcmp(buf, "Text"), "expected Text, got %s\n", buf);
503     DestroyWindow(hwndStatus);
504 }
505 
506 /* Notify events to parent */
507 static BOOL g_got_dblclk;
508 static BOOL g_got_click;
509 static BOOL g_got_rdblclk;
510 static BOOL g_got_rclick;
511 
512 /* Messages to parent */
513 static BOOL g_got_contextmenu;
514 
515 static LRESULT WINAPI test_notify_parent_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
516 {
517    switch(msg)
518    {
519        case WM_NOTIFY:
520        {
521            NMHDR *hdr = ((LPNMHDR)lParam);
522            switch(hdr->code)
523            {
524                case NM_DBLCLK: g_got_dblclk = TRUE; break;
525                case NM_CLICK: g_got_click = TRUE; break;
526                case NM_RDBLCLK: g_got_rdblclk = TRUE; break;
527                case NM_RCLICK: g_got_rclick = TRUE; break;
528            }
529 
530            /* Return zero to indicate default processing */
531            return 0;
532        }
533 
534        case WM_CONTEXTMENU: g_got_contextmenu = TRUE; return 0;
535 
536        default:
537             return( DefWindowProcA(hwnd, msg, wParam, lParam));
538    }
539 
540    return 0;
541 }
542 
543 /* Test that WM_NOTIFY messages from the status control works correctly */
544 static void test_notify(void)
545 {
546     HWND hwndParent;
547     HWND hwndStatus;
548     ATOM atom;
549     WNDCLASSA wclass = {0};
550     wclass.lpszClassName = "TestNotifyParentClass";
551     wclass.lpfnWndProc   = test_notify_parent_proc;
552     atom = RegisterClassA(&wclass);
553     ok(atom, "RegisterClass failed\n");
554 
555     /* create parent */
556     hwndParent = CreateWindowA(wclass.lpszClassName, "parent", WS_OVERLAPPEDWINDOW,
557       CW_USEDEFAULT, 0, 300, 20, NULL, NULL, NULL, NULL);
558     ok(hwndParent != NULL, "Parent creation failed!\n");
559 
560     /* create status bar */
561     hwndStatus = CreateWindowA(STATUSCLASSNAMEA, NULL, WS_VISIBLE | WS_CHILD,
562       0, 0, 300, 20, hwndParent, NULL, NULL, NULL);
563     ok(hwndStatus != NULL, "Status creation failed!\n");
564 
565     /* Send various mouse event, and check that we get them */
566     g_got_dblclk = FALSE;
567     SendMessageA(hwndStatus, WM_LBUTTONDBLCLK, 0, 0);
568     ok(g_got_dblclk, "WM_LBUTTONDBLCLK was not processed correctly!\n");
569     g_got_rdblclk = FALSE;
570     SendMessageA(hwndStatus, WM_RBUTTONDBLCLK, 0, 0);
571     ok(g_got_rdblclk, "WM_RBUTTONDBLCLK was not processed correctly!\n");
572     g_got_click = FALSE;
573     SendMessageA(hwndStatus, WM_LBUTTONUP, 0, 0);
574     ok(g_got_click, "WM_LBUTTONUP was not processed correctly!\n");
575 
576     /* For R-UP, check that we also get the context menu from the default processing */
577     g_got_contextmenu = FALSE;
578     g_got_rclick = FALSE;
579     SendMessageA(hwndStatus, WM_RBUTTONUP, 0, 0);
580     ok(g_got_rclick, "WM_RBUTTONUP was not processed correctly!\n");
581     ok(g_got_contextmenu, "WM_RBUTTONUP did not activate the context menu!\n");
582 }
583 
584 START_TEST(status)
585 {
586     hinst = GetModuleHandleA(NULL);
587 
588     g_hMainWnd = CreateWindowExA(0, "static", "", WS_OVERLAPPEDWINDOW,
589       CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
590       226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
591       NULL, NULL, GetModuleHandleA(NULL), 0);
592 
593     InitCommonControls();
594 
595     register_subclass();
596 
597     test_status_control();
598     test_create();
599     test_height();
600     test_status_ownerdraw();
601     test_gettext();
602     test_notify();
603 }
604