da21924da94c961042b7f4177864b6b50676316c
[reactos.git] / rostests / winetests / comctl32 / toolbar.c
1 /* Unit tests for toolbar.
2 *
3 * Copyright 2005 Krzysztof Foltman
4 * Copyright 2007 Mikolaj Zalewski
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 <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winnls.h"
28 #include "winreg.h"
29 #include "commctrl.h"
30
31 #include "resources.h"
32
33 #include "wine/test.h"
34
35 #include "msg.h"
36
37 #define PARENT_SEQ_INDEX 0
38 #define NUM_MSG_SEQUENCES 1
39
40 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
41
42 static HWND hMainWnd;
43 static BOOL g_fBlockHotItemChange;
44 static BOOL g_fReceivedHotItemChange;
45 static BOOL g_fExpectedHotItemOld;
46 static BOOL g_fExpectedHotItemNew;
47 static DWORD g_dwExpectedDispInfoMask;
48 static BOOL g_ResetDispTextPtr;
49
50 static const struct message ttgetdispinfo_parent_seq[] = {
51 { WM_NOTIFY, sent|id, 0, 0, TBN_GETINFOTIPA },
52 /* next line is todo, currently TTN_GETDISPINFOW is raised here */
53 { WM_NOTIFY, sent|id, 0, 0, TTN_GETDISPINFOA },
54 { 0 }
55 };
56
57 #define DEFINE_EXPECT(func) \
58 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
59
60 #define CHECK_EXPECT2(func) \
61 do { \
62 ok(expect_ ##func, "unexpected call " #func "\n"); \
63 called_ ## func = TRUE; \
64 }while(0)
65
66 #define CHECK_CALLED(func) \
67 do { \
68 ok(called_ ## func, "expected " #func "\n"); \
69 expect_ ## func = called_ ## func = FALSE; \
70 }while(0)
71
72 #define SET_EXPECT(func) \
73 expect_ ## func = TRUE
74
75 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
76
77 #define check_rect(name, val, exp, ...) ok(val.top == exp.top && val.bottom == exp.bottom && \
78 val.left == exp.left && val.right == exp.right, "invalid rect (%d,%d) (%d,%d) - expected (%d,%d) (%d,%d) - (" name ")\n", \
79 val.left, val.top, val.right, val.bottom, exp.left, exp.top, exp.right, exp.bottom, __VA_ARGS__);
80
81 #define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp));
82
83 #define check_button_size(handle, width, height, ...) {\
84 LRESULT bsize = SendMessageA(handle, TB_GETBUTTONSIZE, 0, 0);\
85 ok(bsize == MAKELONG(width, height), "Unexpected button size - got size (%d, %d), expected (%d, %d)\n", LOWORD(bsize), HIWORD(bsize), width, height);\
86 }
87
88 static void MakeButton(TBBUTTON *p, int idCommand, int fsStyle, int nString) {
89 p->iBitmap = -2;
90 p->idCommand = idCommand;
91 p->fsState = TBSTATE_ENABLED;
92 p->fsStyle = fsStyle;
93 p->iString = nString;
94 }
95
96 static LRESULT parent_wnd_notify(LPARAM lParam)
97 {
98 NMHDR *hdr = (NMHDR *)lParam;
99 NMTBHOTITEM *nmhi;
100 NMTBDISPINFOA *nmdisp;
101 switch (hdr->code)
102 {
103 case TBN_HOTITEMCHANGE:
104 nmhi = (NMTBHOTITEM *)lParam;
105 g_fReceivedHotItemChange = TRUE;
106 if (g_fExpectedHotItemOld != g_fExpectedHotItemNew)
107 {
108 compare(nmhi->idOld, g_fExpectedHotItemOld, "%d");
109 compare(nmhi->idNew, g_fExpectedHotItemNew, "%d");
110 }
111 if (g_fBlockHotItemChange)
112 return 1;
113 break;
114
115 case TBN_GETDISPINFOA:
116 ok(FALSE, "TBN_GETDISPINFOA received\n");
117 break;
118
119 case TBN_GETINFOTIPA:
120 {
121 NMTBGETINFOTIPA *tbgit = (NMTBGETINFOTIPA*)lParam;
122
123 if (g_ResetDispTextPtr)
124 {
125 tbgit->pszText = NULL;
126 return 0;
127 }
128 break;
129 }
130 case TBN_GETDISPINFOW:
131 nmdisp = (NMTBDISPINFOA *)lParam;
132
133 compare(nmdisp->dwMask, g_dwExpectedDispInfoMask, "%x");
134 ok(nmdisp->pszText == NULL, "pszText is not NULL\n");
135 break;
136 }
137 return 0;
138 }
139
140 static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
141 {
142 static LONG defwndproc_counter = 0;
143 struct message msg;
144 LRESULT ret;
145
146 msg.message = message;
147 msg.flags = sent|wparam|lparam;
148 if (defwndproc_counter) msg.flags |= defwinproc;
149 msg.wParam = wParam;
150 msg.lParam = lParam;
151 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
152
153 /* log system messages, except for painting */
154 if (message < WM_USER &&
155 message != WM_PAINT &&
156 message != WM_ERASEBKGND &&
157 message != WM_NCPAINT &&
158 message != WM_NCHITTEST &&
159 message != WM_GETTEXT &&
160 message != WM_GETICON &&
161 message != WM_DEVICECHANGE)
162 {
163 add_message(sequences, PARENT_SEQ_INDEX, &msg);
164 }
165
166 switch (message)
167 {
168 case WM_NOTIFY:
169 return parent_wnd_notify(lParam);
170 }
171
172 defwndproc_counter++;
173 ret = DefWindowProcA(hWnd, message, wParam, lParam);
174 defwndproc_counter--;
175
176 return ret;
177 }
178
179 static void basic_test(void)
180 {
181 TBBUTTON buttons[9];
182 HWND hToolbar;
183 int i;
184
185 for (i=0; i<9; i++)
186 MakeButton(buttons+i, 1000+i, TBSTYLE_CHECKGROUP, 0);
187 MakeButton(buttons+3, 1003, TBSTYLE_SEP|TBSTYLE_GROUP, 0);
188 MakeButton(buttons+6, 1006, TBSTYLE_SEP, 0);
189
190 hToolbar = CreateToolbarEx(hMainWnd,
191 WS_VISIBLE | WS_CLIPCHILDREN | CCS_TOP |
192 WS_CHILD | TBSTYLE_LIST,
193 100,
194 0, NULL, 0,
195 buttons, sizeof(buttons)/sizeof(buttons[0]),
196 0, 0, 20, 16, sizeof(TBBUTTON));
197 ok(hToolbar != NULL, "Toolbar creation\n");
198 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"test\000");
199
200 /* test for exclusion working inside a separator-separated :-) group */
201 SendMessageA(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 */
202 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
203 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1001, 0), "A2 not pressed\n");
204
205 SendMessageA(hToolbar, TB_CHECKBUTTON, 1004, 1); /* press A5, release A1 */
206 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 pressed\n");
207 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 not pressed anymore\n");
208
209 SendMessageA(hToolbar, TB_CHECKBUTTON, 1005, 1); /* press A6, release A5 */
210 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
211 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 not pressed anymore\n");
212
213 /* test for inter-group crosstalk, ie. two radio groups interfering with each other */
214 SendMessageA(hToolbar, TB_CHECKBUTTON, 1007, 1); /* press B2 */
215 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
216 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 still not pressed\n");
217 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 pressed\n");
218
219 SendMessageA(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 and ensure B group didn't suffer */
220 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 not pressed anymore\n");
221 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
222 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 still pressed\n");
223
224 SendMessageA(hToolbar, TB_CHECKBUTTON, 1008, 1); /* press B3, and ensure A group didn't suffer */
225 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
226 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
227 ok(!SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 not pressed\n");
228 ok(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 1008, 0), "B3 pressed\n");
229
230 /* tests with invalid index */
231 compare(SendMessageA(hToolbar, TB_ISBUTTONCHECKED, 0xdeadbeef, 0), -1L, "%ld");
232 compare(SendMessageA(hToolbar, TB_ISBUTTONPRESSED, 0xdeadbeef, 0), -1L, "%ld");
233 compare(SendMessageA(hToolbar, TB_ISBUTTONENABLED, 0xdeadbeef, 0), -1L, "%ld");
234 compare(SendMessageA(hToolbar, TB_ISBUTTONINDETERMINATE, 0xdeadbeef, 0), -1L, "%ld");
235 compare(SendMessageA(hToolbar, TB_ISBUTTONHIGHLIGHTED, 0xdeadbeef, 0), -1L, "%ld");
236 compare(SendMessageA(hToolbar, TB_ISBUTTONHIDDEN, 0xdeadbeef, 0), -1L, "%ld");
237
238 DestroyWindow(hToolbar);
239 }
240
241 static void rebuild_toolbar(HWND *hToolbar)
242 {
243 if (*hToolbar)
244 DestroyWindow(*hToolbar);
245 *hToolbar = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
246 hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
247 ok(*hToolbar != NULL, "Toolbar creation problem\n");
248 ok(SendMessageA(*hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n");
249 ok(SendMessageA(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
250 ok(SendMessageA(*hToolbar, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0)==1, "WM_SETFONT\n");
251 }
252
253 static void rebuild_toolbar_with_buttons(HWND *hToolbar)
254 {
255 TBBUTTON buttons[5];
256 rebuild_toolbar(hToolbar);
257
258 ZeroMemory(&buttons, sizeof(buttons));
259 buttons[0].idCommand = 1;
260 buttons[0].fsStyle = BTNS_BUTTON;
261 buttons[0].fsState = TBSTATE_ENABLED;
262 buttons[0].iString = -1;
263 buttons[1].idCommand = 3;
264 buttons[1].fsStyle = BTNS_BUTTON;
265 buttons[1].fsState = TBSTATE_ENABLED;
266 buttons[1].iString = -1;
267 buttons[2].idCommand = 5;
268 buttons[2].fsStyle = BTNS_SEP;
269 buttons[2].fsState = TBSTATE_ENABLED;
270 buttons[2].iString = -1;
271 buttons[3].idCommand = 7;
272 buttons[3].fsStyle = BTNS_BUTTON;
273 buttons[3].fsState = TBSTATE_ENABLED;
274 buttons[3].iString = -1;
275 buttons[4].idCommand = 9;
276 buttons[4].fsStyle = BTNS_BUTTON;
277 buttons[4].fsState = 0; /* disabled */
278 buttons[4].iString = -1;
279 ok(SendMessageA(*hToolbar, TB_ADDBUTTONSA, 5, (LPARAM)buttons) == 1, "TB_ADDBUTTONSA failed\n");
280 ok(SendMessageA(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
281 }
282
283 static void add_128x15_bitmap(HWND hToolbar, int nCmds)
284 {
285 TBADDBITMAP bmp128;
286 bmp128.hInst = GetModuleHandleA(NULL);
287 bmp128.nID = IDB_BITMAP_128x15;
288 ok(SendMessageA(hToolbar, TB_ADDBITMAP, nCmds, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
289 }
290
291 #define CHECK_IMAGELIST(count, dx, dy) { \
292 int cx, cy; \
293 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
294 ok(himl != NULL, "No image list\n"); \
295 if (himl != NULL) {\
296 ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
297 ImageList_GetIconSize(himl, &cx, &cy); \
298 ok(cx == dx && cy == dy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
299 } \
300 }
301
302 static void test_add_bitmap(void)
303 {
304 HWND hToolbar = NULL;
305 TBADDBITMAP bmp128;
306 TBADDBITMAP bmp80;
307 TBADDBITMAP stdsmall;
308 TBADDBITMAP addbmp;
309 HIMAGELIST himl;
310 INT ret;
311
312 /* empty 128x15 bitmap */
313 bmp128.hInst = GetModuleHandleA(NULL);
314 bmp128.nID = IDB_BITMAP_128x15;
315
316 /* empty 80x15 bitmap */
317 bmp80.hInst = GetModuleHandleA(NULL);
318 bmp80.nID = IDB_BITMAP_80x15;
319
320 /* standard bitmap - 240x15 pixels */
321 stdsmall.hInst = HINST_COMMCTRL;
322 stdsmall.nID = IDB_STD_SMALL_COLOR;
323
324 rebuild_toolbar(&hToolbar);
325 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
326 CHECK_IMAGELIST(8, 16, 16);
327
328 /* adding more bitmaps */
329 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 8, "TB_ADDBITMAP - unexpected return\n");
330 CHECK_IMAGELIST(13, 16, 16);
331 /* adding the same bitmap will simply return the index of the already loaded block */
332 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128);
333 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
334 CHECK_IMAGELIST(13, 16, 16);
335 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
336 ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
337 CHECK_IMAGELIST(13, 16, 16);
338 /* even if we increase the wParam */
339 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 55, (LPARAM)&bmp80);
340 ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
341 CHECK_IMAGELIST(13, 16, 16);
342
343 /* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
344 rebuild_toolbar(&hToolbar);
345 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
346 CHECK_IMAGELIST(8, 16, 16);
347 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
348 ok(ret == 3, "TB_ADDBITMAP - unexpected return %d\n", ret);
349 /* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
350 CHECK_IMAGELIST(13, 16, 16);
351
352 /* the same for negative wParam */
353 rebuild_toolbar(&hToolbar);
354 ret = SendMessageA(hToolbar, TB_ADDBITMAP, -143, (LPARAM)&bmp128);
355 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
356 CHECK_IMAGELIST(8, 16, 16);
357 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
358 ok(ret == -143, "TB_ADDBITMAP - unexpected return %d\n", ret);
359 CHECK_IMAGELIST(13, 16, 16);
360
361 /* for zero only one bitmap will be added */
362 rebuild_toolbar(&hToolbar);
363 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&bmp80);
364 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
365 CHECK_IMAGELIST(1, 16, 16);
366
367 /* if wParam is larger than the amount of icons, the list is grown */
368 rebuild_toolbar(&hToolbar);
369 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
370 CHECK_IMAGELIST(100, 16, 16);
371 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128);
372 ok(ret == 100, "TB_ADDBITMAP - unexpected return %d\n", ret);
373 CHECK_IMAGELIST(200, 16, 16);
374
375 /* adding built-in items - the wParam is ignored */
376 rebuild_toolbar(&hToolbar);
377 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
378 CHECK_IMAGELIST(5, 16, 16);
379 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 5, "TB_ADDBITMAP - unexpected return\n");
380 CHECK_IMAGELIST(20, 16, 16);
381 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 20, "TB_ADDBITMAP - unexpected return\n");
382 CHECK_IMAGELIST(28, 16, 16);
383
384 /* when we increase the bitmap size, less icons will be created */
385 rebuild_toolbar(&hToolbar);
386 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20)) == TRUE, "TB_SETBITMAPSIZE failed\n");
387 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
388 CHECK_IMAGELIST(6, 20, 20);
389 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
390 ok(ret == 1, "TB_ADDBITMAP - unexpected return %d\n", ret);
391 CHECK_IMAGELIST(10, 20, 20);
392 /* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
393 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
394 UpdateWindow(hToolbar);
395 CHECK_IMAGELIST(26, 8, 8);
396 /* loading a standard bitmaps automatically resizes the icons */
397 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&stdsmall) == 2, "TB_ADDBITMAP - unexpected return\n");
398 UpdateWindow(hToolbar);
399 CHECK_IMAGELIST(28, 16, 16);
400
401 /* two more SETBITMAPSIZE tests */
402 rebuild_toolbar(&hToolbar);
403 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
404 CHECK_IMAGELIST(100, 16, 16);
405 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 100, "TB_ADDBITMAP - unexpected return\n");
406 CHECK_IMAGELIST(200, 16, 16);
407 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
408 UpdateWindow(hToolbar);
409 CHECK_IMAGELIST(200, 8, 8);
410 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(30, 30)) == TRUE, "TB_SETBITMAPSIZE failed\n");
411 UpdateWindow(hToolbar);
412 CHECK_IMAGELIST(200, 30, 30);
413 rebuild_toolbar(&hToolbar);
414 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
415 CHECK_IMAGELIST(8, 16, 16);
416 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp80) == 5, "TB_ADDBITMAP - unexpected return\n");
417 CHECK_IMAGELIST(13, 16, 16);
418 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(30, 30)) == TRUE, "TB_SETBITMAPSIZE failed\n");
419 UpdateWindow(hToolbar);
420 CHECK_IMAGELIST(8, 30, 30);
421 /* when the width or height is zero, set it to 1 */
422 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(0, 0)) == TRUE, "TB_SETBITMAPSIZE failed\n");
423 UpdateWindow(hToolbar);
424 CHECK_IMAGELIST(208, 1, 1);
425 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(0, 5)) == TRUE, "TB_SETBITMAPSIZE failed\n");
426 UpdateWindow(hToolbar);
427 CHECK_IMAGELIST(208, 1, 5);
428 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(5, 0)) == TRUE, "TB_SETBITMAPSIZE failed\n");
429 UpdateWindow(hToolbar);
430 CHECK_IMAGELIST(41, 5, 1);
431
432 /* the control can add bitmaps to an existing image list */
433 rebuild_toolbar(&hToolbar);
434 himl = ImageList_LoadImageA(GetModuleHandleA(NULL), (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP_80x15),
435 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
436 ok(himl != NULL, "failed to create imagelist\n");
437 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
438 CHECK_IMAGELIST(4, 20, 15);
439 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
440 CHECK_IMAGELIST(10, 20, 15);
441 /* however TB_SETBITMAPSIZE/add std bitmap won't change the image size (the button size does change) */
442 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
443 UpdateWindow(hToolbar);
444 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(15, 14), "%x");
445 CHECK_IMAGELIST(10, 20, 15);
446 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 1, "TB_SETBITMAPSIZE failed\n");
447 UpdateWindow(hToolbar);
448 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(23, 22), "%x");
449 CHECK_IMAGELIST(22, 20, 15);
450
451 /* check standard bitmaps */
452 addbmp.hInst = HINST_COMMCTRL;
453 addbmp.nID = IDB_STD_SMALL_COLOR;
454 rebuild_toolbar(&hToolbar);
455 ImageList_Destroy(himl);
456
457 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
458 CHECK_IMAGELIST(15, 16, 16);
459 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(23, 22), "%x");
460 addbmp.nID = IDB_STD_LARGE_COLOR;
461 rebuild_toolbar(&hToolbar);
462 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
463 CHECK_IMAGELIST(15, 24, 24);
464 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(31, 30), "%x");
465
466 addbmp.nID = IDB_VIEW_SMALL_COLOR;
467 rebuild_toolbar(&hToolbar);
468 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
469 CHECK_IMAGELIST(12, 16, 16);
470 addbmp.nID = IDB_VIEW_LARGE_COLOR;
471 rebuild_toolbar(&hToolbar);
472 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
473 CHECK_IMAGELIST(12, 24, 24);
474
475 addbmp.nID = IDB_HIST_SMALL_COLOR;
476 rebuild_toolbar(&hToolbar);
477 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
478 CHECK_IMAGELIST(5, 16, 16);
479 addbmp.nID = IDB_HIST_LARGE_COLOR;
480 rebuild_toolbar(&hToolbar);
481 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
482 CHECK_IMAGELIST(5, 24, 24);
483
484
485 DestroyWindow(hToolbar);
486 }
487
488 #define CHECK_STRING_TABLE(count, tab) { \
489 INT _i; \
490 CHAR _buf[260]; \
491 for (_i = 0; _i < (count); _i++) {\
492 ret = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(260, _i), (LPARAM)_buf); \
493 ok(ret >= 0, "TB_GETSTRINGA - unexpected return %d while checking string %d\n", ret, _i); \
494 if (ret >= 0) \
495 ok(strcmp(_buf, (tab)[_i]) == 0, "Invalid string #%d - '%s' vs '%s'\n", _i, (tab)[_i], _buf); \
496 } \
497 ok(SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(260, (count)), (LPARAM)_buf) == -1, \
498 "Too many strings in table\n"); \
499 }
500
501 static void test_add_string(void)
502 {
503 LPCSTR test1 = "a\0b\0";
504 LPCSTR test2 = "|a|b||\0";
505 LPCSTR ret1[] = {"a", "b"};
506 LPCSTR ret2[] = {"a", "b", "|a|b||"};
507 LPCSTR ret3[] = {"a", "b", "|a|b||", "p", "q"};
508 LPCSTR ret4[] = {"a", "b", "|a|b||", "p", "q", "p"};
509 LPCSTR ret5[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q"};
510 LPCSTR ret6[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q"};
511 LPCSTR ret7[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q", "br", "c", "d"};
512 HWND hToolbar = NULL;
513 TBBUTTON button;
514 int ret;
515 CHAR buf[260];
516
517 rebuild_toolbar(&hToolbar);
518 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)test1);
519 ok(ret == 0, "TB_ADDSTRINGA - unexpected return %d\n", ret);
520 ret = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(260, 1), (LPARAM)buf);
521 if (ret == 0)
522 {
523 win_skip("TB_GETSTRINGA needs 5.80\n");
524 return;
525 }
526 CHECK_STRING_TABLE(2, ret1);
527 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)test2);
528 ok(ret == 2, "TB_ADDSTRINGA - unexpected return %d\n", ret);
529 CHECK_STRING_TABLE(3, ret2);
530
531 /* null instance handle */
532 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, IDS_TBADD1);
533 ok(ret == -1, "TB_ADDSTRINGA - unexpected return %d\n", ret);
534
535 /* invalid instance handle */
536 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0xdeadbeef, IDS_TBADD1);
537 ok(ret == -1, "TB_ADDSTRINGA - unexpected return %d\n", ret);
538
539 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandleA(NULL), IDS_TBADD1);
540 ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
541 CHECK_STRING_TABLE(3, ret2);
542 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandleA(NULL), IDS_TBADD2);
543 ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
544 CHECK_STRING_TABLE(5, ret3);
545 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandleA(NULL), IDS_TBADD3);
546 ok(ret == 5, "TB_ADDSTRINGA - unexpected return %d\n", ret);
547 CHECK_STRING_TABLE(6, ret4);
548 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandleA(NULL), IDS_TBADD4);
549 ok(ret == 6, "TB_ADDSTRINGA - unexpected return %d\n", ret);
550 CHECK_STRING_TABLE(8, ret5);
551 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandleA(NULL), IDS_TBADD5);
552 ok(ret == 8, "TB_ADDSTRINGA - unexpected return %d\n", ret);
553 CHECK_STRING_TABLE(11, ret6);
554 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandleA(NULL), IDS_TBADD7);
555 ok(ret == 11, "TB_ADDSTRINGA - unexpected return %d\n", ret);
556 CHECK_STRING_TABLE(14, ret7);
557
558 ZeroMemory(&button, sizeof(button));
559 button.iString = (UINT_PTR)"Test";
560 SendMessageA(hToolbar, TB_INSERTBUTTONA, 0, (LPARAM)&button);
561 CHECK_STRING_TABLE(14, ret7);
562 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&button);
563 CHECK_STRING_TABLE(14, ret7);
564
565 DestroyWindow(hToolbar);
566 }
567
568 static void expect_hot_notify(int idold, int idnew)
569 {
570 g_fExpectedHotItemOld = idold;
571 g_fExpectedHotItemNew = idnew;
572 g_fReceivedHotItemChange = FALSE;
573 }
574
575 #define check_hot_notify() \
576 ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n"); \
577 g_fExpectedHotItemOld = g_fExpectedHotItemNew = 0;
578
579 static void test_hotitem(void)
580 {
581 HWND hToolbar = NULL;
582 TBBUTTONINFOA tbinfo;
583 LRESULT ret;
584
585 g_fBlockHotItemChange = FALSE;
586
587 rebuild_toolbar_with_buttons(&hToolbar);
588 /* set TBSTYLE_FLAT. comctl5 allows hot items only for such toolbars.
589 * comctl6 doesn't have this requirement even when theme == NULL */
590 SetWindowLongA(hToolbar, GWL_STYLE, TBSTYLE_FLAT | GetWindowLongA(hToolbar, GWL_STYLE));
591 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
592 ok(ret == -1, "Hot item: %ld, expected -1\n", ret);
593 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 1, 0);
594 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
595 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
596 ok(ret == 1, "Hot item: %ld, expected 1\n", ret);
597 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 2, 0);
598 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
599
600 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 0xbeef, 0);
601 ok(ret == 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
602 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
603 ok(ret == 2, "Hot item: %lx, expected 2\n", ret);
604 ret = SendMessageA(hToolbar, TB_SETHOTITEM, -0xbeef, 0);
605 ok(ret == 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
606 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
607 ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
608
609 expect_hot_notify(0, 7);
610 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 3, 0);
611 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
612 check_hot_notify();
613 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
614 ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
615 g_fBlockHotItemChange = TRUE;
616 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 2, 0);
617 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
618 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
619 ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
620 g_fBlockHotItemChange = FALSE;
621
622 g_fReceivedHotItemChange = FALSE;
623 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 0xbeaf, 0);
624 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
625 ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received for invalid parameter\n");
626
627 g_fReceivedHotItemChange = FALSE;
628 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 3, 0);
629 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
630 ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received after a duplication\n");
631
632 expect_hot_notify(7, 0);
633 ret = SendMessageA(hToolbar, TB_SETHOTITEM, -0xbeaf, 0);
634 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
635 check_hot_notify();
636 SendMessageA(hToolbar, TB_SETHOTITEM, 3, 0);
637
638 /* setting disabled buttons will generate a notify with the button id but no button will be hot */
639 expect_hot_notify(7, 9);
640 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 4, 0);
641 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
642 check_hot_notify();
643 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
644 ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
645 /* enabling the button won't change that */
646 SendMessageA(hToolbar, TB_ENABLEBUTTON, 9, TRUE);
647 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
648 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
649
650 /* disabling a hot button works */
651 ret = SendMessageA(hToolbar, TB_SETHOTITEM, 3, 0);
652 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
653 g_fReceivedHotItemChange = FALSE;
654 SendMessageA(hToolbar, TB_ENABLEBUTTON, 7, FALSE);
655 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
656 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
657 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
658
659 SendMessageA(hToolbar, TB_SETHOTITEM, 1, 0);
660 tbinfo.cbSize = sizeof(TBBUTTONINFOA);
661 tbinfo.dwMask = TBIF_STATE;
662 tbinfo.fsState = 0; /* disabled */
663 g_fReceivedHotItemChange = FALSE;
664 ok(SendMessageA(hToolbar, TB_SETBUTTONINFOA, 1, (LPARAM)&tbinfo) == TRUE, "TB_SETBUTTONINFOA failed\n");
665 ret = SendMessageA(hToolbar, TB_GETHOTITEM, 0, 0);
666 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
667 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
668
669 DestroyWindow(hToolbar);
670 }
671
672 #if 0 /* use this to generate more tests*/
673
674 static void dump_sizes(HWND hToolbar)
675 {
676 SIZE sz;
677 RECT r;
678 int count = SendMessageA(hToolbar, TB_BUTTONCOUNT, 0, 0);
679 int i;
680
681 GetClientRect(hToolbar, &r);
682 SendMessageA(hToolbar, TB_GETMAXSIZE, 0, &sz);
683 printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r.left, r.top, r.right, r.bottom,
684 sz.cx, sz.cy, count);
685 for (i=0; i<count; i++)
686 {
687 SendMessageA(hToolbar, TB_GETITEMRECT, i, &r);
688 printf("%s{%3d, %3d, %3d, %3d}, ", (i%3==0 ? "\n " : ""), r.left, r.top, r.right, r.bottom);
689 }
690 printf("\n }, },\n");
691 }
692
693 #define check_sizes() dump_sizes(hToolbar);
694 #define check_sizes_todo(todomask) dump_sizes(hToolbar);
695
696 #else
697
698 static int system_font_height(void) {
699 HDC hDC;
700 TEXTMETRICA tm;
701
702 hDC = CreateCompatibleDC(NULL);
703 GetTextMetricsA(hDC, &tm);
704 DeleteDC(NULL);
705
706 return tm.tmHeight;
707 }
708
709 static int string_width(const CHAR *s) {
710 SIZE sz;
711 HDC hdc;
712
713 hdc = CreateCompatibleDC(NULL);
714 GetTextExtentPoint32A(hdc, s, strlen(s), &sz);
715 DeleteDC(hdc);
716
717 return sz.cx;
718 }
719
720 typedef struct
721 {
722 RECT rcClient;
723 SIZE szMin;
724 INT nButtons;
725 RECT *prcButtons;
726 } tbsize_result_t;
727
728 static tbsize_result_t init_tbsize_result(int nButtonsAlloc, int cleft, int ctop, int cright, int cbottom, int minx, int miny) {
729 tbsize_result_t ret;
730
731 SetRect(&ret.rcClient, cleft, ctop, cright, cbottom);
732 ret.szMin.cx = minx;
733 ret.szMin.cy = miny;
734 ret.nButtons = 0;
735 ret.prcButtons = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nButtonsAlloc*sizeof(RECT));
736
737 return ret;
738 }
739
740 static void tbsize_addbutton(tbsize_result_t *tbsr, int left, int top, int right, int bottom) {
741 SetRect(&tbsr->prcButtons[tbsr->nButtons], left, top, right, bottom);
742 tbsr->nButtons++;
743 }
744
745 #define STRING0 "A"
746 #define STRING1 "MMMMMMMMMMMMM"
747 #define STRING2 "Tst"
748
749 static tbsize_result_t *tbsize_results;
750
751 #define tbsize_results_num 24
752
753 static void init_tbsize_results(void) {
754 int fontheight = system_font_height();
755 int buttonwidth;
756
757 tbsize_results = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, tbsize_results_num*sizeof(tbsize_result_t));
758
759 tbsize_results[0] = init_tbsize_result(5, 0, 0 ,672 ,26, 100 ,22);
760 tbsize_addbutton(&tbsize_results[0], 0, 2, 23, 24);
761 tbsize_addbutton(&tbsize_results[0], 23, 2, 46, 24);
762 tbsize_addbutton(&tbsize_results[0], 46, 2, 54, 24);
763 tbsize_addbutton(&tbsize_results[0], 54, 2, 77, 24);
764 tbsize_addbutton(&tbsize_results[0], 77, 2, 100, 24);
765
766 tbsize_results[1] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
767 tbsize_addbutton(&tbsize_results[1], 0, 2, 23, 24);
768 tbsize_addbutton(&tbsize_results[1], 23, 2, 46, 24);
769 tbsize_addbutton(&tbsize_results[1], 46, 2, 54, 24);
770 tbsize_addbutton(&tbsize_results[1], 54, 2, 77, 24);
771 tbsize_addbutton(&tbsize_results[1], 77, 2, 100, 24);
772 tbsize_addbutton(&tbsize_results[1], 100, 2, 123, 24);
773 tbsize_addbutton(&tbsize_results[1], 0, 24, 23, 46);
774
775 tbsize_results[2] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
776 tbsize_addbutton(&tbsize_results[2], 0, 2, 23, 24);
777 tbsize_addbutton(&tbsize_results[2], 23, 2, 46, 24);
778 tbsize_addbutton(&tbsize_results[2], 46, 2, 54, 24);
779 tbsize_addbutton(&tbsize_results[2], 54, 2, 77, 24);
780 tbsize_addbutton(&tbsize_results[2], 77, 2, 100, 24);
781 tbsize_addbutton(&tbsize_results[2], 100, 2, 123, 24);
782 tbsize_addbutton(&tbsize_results[2], 0, 24, 23, 46);
783
784 tbsize_results[3] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
785 tbsize_addbutton(&tbsize_results[3], 0, 2, 23, 24);
786 tbsize_addbutton(&tbsize_results[3], 23, 2, 46, 24);
787 tbsize_addbutton(&tbsize_results[3], 46, 2, 54, 24);
788 tbsize_addbutton(&tbsize_results[3], 54, 2, 77, 24);
789 tbsize_addbutton(&tbsize_results[3], 77, 2, 100, 24);
790 tbsize_addbutton(&tbsize_results[3], 100, 2, 123, 24);
791 tbsize_addbutton(&tbsize_results[3], 123, 2, 146, 24);
792
793 tbsize_results[4] = init_tbsize_result(9, 0, 0, 672, 26, 192, 22);
794 tbsize_addbutton(&tbsize_results[4], 0, 2, 23, 24);
795 tbsize_addbutton(&tbsize_results[4], 23, 2, 46, 24);
796 tbsize_addbutton(&tbsize_results[4], 46, 2, 54, 24);
797 tbsize_addbutton(&tbsize_results[4], 54, 2, 77, 24);
798 tbsize_addbutton(&tbsize_results[4], 77, 2, 100, 24);
799 tbsize_addbutton(&tbsize_results[4], 100, 2, 123, 24);
800 tbsize_addbutton(&tbsize_results[4], 123, 2, 146, 24);
801 tbsize_addbutton(&tbsize_results[4], 146, 2, 169, 24);
802 tbsize_addbutton(&tbsize_results[4], 169, 2, 192, 24);
803
804 tbsize_results[5] = init_tbsize_result(39, 0, 0, 672, 92, 882, 22);
805 tbsize_addbutton(&tbsize_results[5], 0, 2, 23, 24);
806 tbsize_addbutton(&tbsize_results[5], 23, 2, 46, 24);
807 tbsize_addbutton(&tbsize_results[5], 0, 2, 8, 29);
808 tbsize_addbutton(&tbsize_results[5], 0, 29, 23, 51);
809 tbsize_addbutton(&tbsize_results[5], 23, 29, 46, 51);
810 tbsize_addbutton(&tbsize_results[5], 46, 29, 69, 51);
811 tbsize_addbutton(&tbsize_results[5], 69, 29, 92, 51);
812 tbsize_addbutton(&tbsize_results[5], 92, 29, 115, 51);
813 tbsize_addbutton(&tbsize_results[5], 115, 29, 138, 51);
814 tbsize_addbutton(&tbsize_results[5], 138, 29, 161, 51);
815 tbsize_addbutton(&tbsize_results[5], 161, 29, 184, 51);
816 tbsize_addbutton(&tbsize_results[5], 184, 29, 207, 51);
817 tbsize_addbutton(&tbsize_results[5], 207, 29, 230, 51);
818 tbsize_addbutton(&tbsize_results[5], 230, 29, 253, 51);
819 tbsize_addbutton(&tbsize_results[5], 253, 29, 276, 51);
820 tbsize_addbutton(&tbsize_results[5], 276, 29, 299, 51);
821 tbsize_addbutton(&tbsize_results[5], 299, 29, 322, 51);
822 tbsize_addbutton(&tbsize_results[5], 322, 29, 345, 51);
823 tbsize_addbutton(&tbsize_results[5], 345, 29, 368, 51);
824 tbsize_addbutton(&tbsize_results[5], 368, 29, 391, 51);
825 tbsize_addbutton(&tbsize_results[5], 391, 29, 414, 51);
826 tbsize_addbutton(&tbsize_results[5], 414, 29, 437, 51);
827 tbsize_addbutton(&tbsize_results[5], 437, 29, 460, 51);
828 tbsize_addbutton(&tbsize_results[5], 460, 29, 483, 51);
829 tbsize_addbutton(&tbsize_results[5], 483, 29, 506, 51);
830 tbsize_addbutton(&tbsize_results[5], 506, 29, 529, 51);
831 tbsize_addbutton(&tbsize_results[5], 529, 29, 552, 51);
832 tbsize_addbutton(&tbsize_results[5], 552, 29, 575, 51);
833 tbsize_addbutton(&tbsize_results[5], 575, 29, 598, 51);
834 tbsize_addbutton(&tbsize_results[5], 598, 29, 621, 51);
835 tbsize_addbutton(&tbsize_results[5], 621, 29, 644, 51);
836 tbsize_addbutton(&tbsize_results[5], 644, 29, 667, 51);
837 tbsize_addbutton(&tbsize_results[5], 0, 51, 23, 73);
838 tbsize_addbutton(&tbsize_results[5], 23, 51, 46, 73);
839 tbsize_addbutton(&tbsize_results[5], 46, 51, 69, 73);
840 tbsize_addbutton(&tbsize_results[5], 69, 51, 92, 73);
841 tbsize_addbutton(&tbsize_results[5], 92, 51, 115, 73);
842 tbsize_addbutton(&tbsize_results[5], 115, 51, 138, 73);
843 tbsize_addbutton(&tbsize_results[5], 138, 51, 161, 73);
844
845 tbsize_results[6] = init_tbsize_result(7, 0, 0, 48, 226, 23, 140);
846 tbsize_addbutton(&tbsize_results[6], 0, 2, 23, 24);
847 tbsize_addbutton(&tbsize_results[6], 23, 2, 46, 24);
848 tbsize_addbutton(&tbsize_results[6], 46, 2, 94, 24);
849 tbsize_addbutton(&tbsize_results[6], 94, 2, 117, 24);
850 tbsize_addbutton(&tbsize_results[6], 117, 2, 140, 24);
851 tbsize_addbutton(&tbsize_results[6], 140, 2, 163, 24);
852 tbsize_addbutton(&tbsize_results[6], 0, 24, 23, 46);
853
854 tbsize_results[7] = init_tbsize_result(7, 0, 0, 92, 226, 23, 140);
855 tbsize_addbutton(&tbsize_results[7], 0, 2, 23, 24);
856 tbsize_addbutton(&tbsize_results[7], 23, 2, 46, 24);
857 tbsize_addbutton(&tbsize_results[7], 0, 24, 92, 32);
858 tbsize_addbutton(&tbsize_results[7], 0, 32, 23, 54);
859 tbsize_addbutton(&tbsize_results[7], 23, 32, 46, 54);
860 tbsize_addbutton(&tbsize_results[7], 46, 32, 69, 54);
861 tbsize_addbutton(&tbsize_results[7], 69, 32, 92, 54);
862
863 tbsize_results[8] = init_tbsize_result(7, 0, 0, 672, 26, 194, 30);
864 tbsize_addbutton(&tbsize_results[8], 0, 2, 31, 32);
865 tbsize_addbutton(&tbsize_results[8], 31, 2, 62, 32);
866 tbsize_addbutton(&tbsize_results[8], 62, 2, 70, 32);
867 tbsize_addbutton(&tbsize_results[8], 70, 2, 101, 32);
868 tbsize_addbutton(&tbsize_results[8], 101, 2, 132, 32);
869 tbsize_addbutton(&tbsize_results[8], 132, 2, 163, 32);
870 tbsize_addbutton(&tbsize_results[8], 0, 32, 31, 62);
871
872 tbsize_results[9] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
873 tbsize_addbutton(&tbsize_results[9], 0, 2, 31, 32);
874 tbsize_addbutton(&tbsize_results[9], 31, 2, 62, 32);
875 tbsize_addbutton(&tbsize_results[9], 62, 2, 70, 32);
876 tbsize_addbutton(&tbsize_results[9], 70, 2, 101, 32);
877 tbsize_addbutton(&tbsize_results[9], 101, 2, 132, 32);
878 tbsize_addbutton(&tbsize_results[9], 132, 2, 163, 32);
879 tbsize_addbutton(&tbsize_results[9], 0, 32, 31, 62);
880
881 tbsize_results[10] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
882 tbsize_addbutton(&tbsize_results[10], 0, 0, 31, 30);
883 tbsize_addbutton(&tbsize_results[10], 31, 0, 62, 30);
884 tbsize_addbutton(&tbsize_results[10], 62, 0, 70, 30);
885 tbsize_addbutton(&tbsize_results[10], 70, 0, 101, 30);
886 tbsize_addbutton(&tbsize_results[10], 101, 0, 132, 30);
887 tbsize_addbutton(&tbsize_results[10], 132, 0, 163, 30);
888 tbsize_addbutton(&tbsize_results[10], 0, 30, 31, 60);
889
890 tbsize_results[11] = init_tbsize_result(7, 0, 0, 124, 226, 31, 188);
891 tbsize_addbutton(&tbsize_results[11], 0, 0, 31, 30);
892 tbsize_addbutton(&tbsize_results[11], 31, 0, 62, 30);
893 tbsize_addbutton(&tbsize_results[11], 0, 30, 124, 38);
894 tbsize_addbutton(&tbsize_results[11], 0, 38, 31, 68);
895 tbsize_addbutton(&tbsize_results[11], 31, 38, 62, 68);
896 tbsize_addbutton(&tbsize_results[11], 62, 38, 93, 68);
897 tbsize_addbutton(&tbsize_results[11], 93, 38, 124, 68);
898
899 tbsize_results[12] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
900 tbsize_addbutton(&tbsize_results[12], 0, 2, 23, 24);
901 tbsize_addbutton(&tbsize_results[12], 23, 2, 46, 24);
902 tbsize_addbutton(&tbsize_results[12], 46, 2, 54, 24);
903 tbsize_addbutton(&tbsize_results[12], 54, 2, 77, 24);
904 tbsize_addbutton(&tbsize_results[12], 77, 2, 100, 24);
905 tbsize_addbutton(&tbsize_results[12], 100, 2, 123, 24);
906 tbsize_addbutton(&tbsize_results[12], 123, 2, 146, 24);
907
908 tbsize_results[13] = init_tbsize_result(7, 0, 0, 672, 26, 146, 100);
909 tbsize_addbutton(&tbsize_results[13], 0, 0, 23, 100);
910 tbsize_addbutton(&tbsize_results[13], 23, 0, 46, 100);
911 tbsize_addbutton(&tbsize_results[13], 46, 0, 54, 100);
912 tbsize_addbutton(&tbsize_results[13], 54, 0, 77, 100);
913 tbsize_addbutton(&tbsize_results[13], 77, 0, 100, 100);
914 tbsize_addbutton(&tbsize_results[13], 100, 0, 123, 100);
915 tbsize_addbutton(&tbsize_results[13], 123, 0, 146, 100);
916
917 tbsize_results[14] = init_tbsize_result(10, 0, 0, 672, 26, 146, 100);
918 tbsize_addbutton(&tbsize_results[14], 0, 0, 23, 100);
919 tbsize_addbutton(&tbsize_results[14], 23, 0, 46, 100);
920 tbsize_addbutton(&tbsize_results[14], 46, 0, 54, 100);
921 tbsize_addbutton(&tbsize_results[14], 54, 0, 77, 100);
922 tbsize_addbutton(&tbsize_results[14], 77, 0, 100, 100);
923 tbsize_addbutton(&tbsize_results[14], 100, 0, 123, 100);
924 tbsize_addbutton(&tbsize_results[14], 123, 0, 146, 100);
925 tbsize_addbutton(&tbsize_results[14], 146, 0, 169, 100);
926 tbsize_addbutton(&tbsize_results[14], 169, 0, 192, 100);
927 tbsize_addbutton(&tbsize_results[14], 192, 0, 215, 100);
928
929 tbsize_results[15] = init_tbsize_result(11, 0, 0, 672, 26, 238, 39);
930 tbsize_addbutton(&tbsize_results[15], 0, 0, 23, 23 + fontheight);
931 tbsize_addbutton(&tbsize_results[15], 23, 0, 46, 23 + fontheight);
932 tbsize_addbutton(&tbsize_results[15], 46, 0, 54, 23 + fontheight);
933 tbsize_addbutton(&tbsize_results[15], 54, 0, 77, 23 + fontheight);
934 tbsize_addbutton(&tbsize_results[15], 77, 0, 100, 23 + fontheight);
935 tbsize_addbutton(&tbsize_results[15], 100, 0, 123, 23 + fontheight);
936 tbsize_addbutton(&tbsize_results[15], 123, 0, 146, 23 + fontheight);
937 tbsize_addbutton(&tbsize_results[15], 146, 0, 169, 23 + fontheight);
938 tbsize_addbutton(&tbsize_results[15], 169, 0, 192, 23 + fontheight);
939 tbsize_addbutton(&tbsize_results[15], 192, 0, 215, 23 + fontheight);
940 tbsize_addbutton(&tbsize_results[15], 215, 0, 238, 23 + fontheight);
941
942 tbsize_results[16] = init_tbsize_result(11, 0, 0, 672, 26, 239, 22);
943 tbsize_addbutton(&tbsize_results[16], 0, 0, 23, 22);
944 tbsize_addbutton(&tbsize_results[16], 23, 0, 46, 22);
945 tbsize_addbutton(&tbsize_results[16], 46, 0, 54, 22);
946 tbsize_addbutton(&tbsize_results[16], 54, 0, 77, 22);
947 tbsize_addbutton(&tbsize_results[16], 77, 0, 100, 22);
948 tbsize_addbutton(&tbsize_results[16], 100, 0, 123, 22);
949 tbsize_addbutton(&tbsize_results[16], 123, 0, 146, 22);
950 tbsize_addbutton(&tbsize_results[16], 146, 0, 169, 22);
951 tbsize_addbutton(&tbsize_results[16], 169, 0, 192, 22);
952 tbsize_addbutton(&tbsize_results[16], 192, 0, 215, 22);
953 tbsize_addbutton(&tbsize_results[16], 215, 0, 238, 22);
954
955 buttonwidth = 7 + string_width(STRING1);
956
957 tbsize_results[17] = init_tbsize_result(3, 0, 0, 672, 26, 489, 39);
958 tbsize_addbutton(&tbsize_results[17], 0, 2, buttonwidth, 25 + fontheight);
959 tbsize_addbutton(&tbsize_results[17], buttonwidth, 2, 2*buttonwidth + 4, 25 + fontheight);
960 tbsize_addbutton(&tbsize_results[17], 2*buttonwidth + 4, 2, 3*buttonwidth + 4, 25 + fontheight);
961
962 tbsize_results[18] = init_tbsize_result(6, 0, 0, 672, 104, 978, 24);
963 tbsize_addbutton(&tbsize_results[18], 0, 2, buttonwidth, 10 + fontheight);
964 tbsize_addbutton(&tbsize_results[18], buttonwidth, 2, 2*buttonwidth, 10 + fontheight);
965 tbsize_addbutton(&tbsize_results[18], 2*buttonwidth, 2, 3*buttonwidth, 10 + fontheight);
966 tbsize_addbutton(&tbsize_results[18], 3*buttonwidth, 2, 4*buttonwidth, 10 + fontheight);
967 tbsize_addbutton(&tbsize_results[18], 4*buttonwidth, 2, 5*buttonwidth + 4, 10 + fontheight);
968 tbsize_addbutton(&tbsize_results[18], 5*buttonwidth + 4, 2, 5*buttonwidth + 4 + string_width(STRING2) + 11, 10 + fontheight);
969
970 tbsize_results[19] = init_tbsize_result(6, 0, 0, 672, 28, 978, 38);
971 tbsize_addbutton(&tbsize_results[19], 0, 0, buttonwidth, 22 + fontheight);
972 tbsize_addbutton(&tbsize_results[19], buttonwidth, 0, 2*buttonwidth, 22 + fontheight);
973 tbsize_addbutton(&tbsize_results[19], 2*buttonwidth, 0, 3*buttonwidth, 22 + fontheight);
974 tbsize_addbutton(&tbsize_results[19], 3*buttonwidth, 0, 4*buttonwidth, 22 + fontheight);
975 tbsize_addbutton(&tbsize_results[19], 4*buttonwidth, 0, 5*buttonwidth + 4, 22 + fontheight);
976 tbsize_addbutton(&tbsize_results[19], 5*buttonwidth + 4, 0, 5*buttonwidth + 4 + string_width(STRING2) + 11, 22 + fontheight);
977
978 tbsize_results[20] = init_tbsize_result(3, 0, 0, 672, 100, 239, 102);
979 tbsize_addbutton(&tbsize_results[20], 0, 2, 100, 102);
980 tbsize_addbutton(&tbsize_results[20], 100, 2, 139, 102);
981 tbsize_addbutton(&tbsize_results[20], 139, 2, 239, 102);
982
983 tbsize_results[21] = init_tbsize_result(3, 0, 0, 672, 42, 185, 40);
984 tbsize_addbutton(&tbsize_results[21], 0, 2, 75, 40);
985 tbsize_addbutton(&tbsize_results[21], 75, 2, 118, 40);
986 tbsize_addbutton(&tbsize_results[21], 118, 2, 165 + string_width(STRING2), 40);
987
988 tbsize_results[22] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
989 tbsize_addbutton(&tbsize_results[22], 0, 2, 47 + string_width(STRING2), 40);
990
991 tbsize_results[23] = init_tbsize_result(2, 0, 0, 672, 42, 67, 41);
992 tbsize_addbutton(&tbsize_results[23], 0, 2, 672, 25 + fontheight);
993 tbsize_addbutton(&tbsize_results[23], 0, 25 + fontheight, 672, 48 + 2*fontheight);
994 }
995
996 static void free_tbsize_results(void) {
997 int i;
998
999 for (i = 0; i < tbsize_results_num; i++)
1000 HeapFree(GetProcessHeap(), 0, tbsize_results[i].prcButtons);
1001 HeapFree(GetProcessHeap(), 0, tbsize_results);
1002 tbsize_results = NULL;
1003 }
1004
1005 static int tbsize_numtests = 0;
1006
1007 typedef struct
1008 {
1009 int test_num;
1010 int rect_index;
1011 RECT rcButton;
1012 } tbsize_alt_result_t;
1013
1014 static tbsize_alt_result_t tbsize_alt_results[] =
1015 {
1016 { 5, 2, { 0, 24, 8, 29 } },
1017 { 20, 1, { 100, 2, 107, 102 } },
1018 { 20, 2, { 107, 2, 207, 102 } }
1019 };
1020
1021 static DWORD tbsize_alt_numtests = 0;
1022
1023 #define check_sizes_todo(todomask) { \
1024 RECT rc; \
1025 int buttonCount, i, mask=(todomask); \
1026 tbsize_result_t *res = &tbsize_results[tbsize_numtests]; \
1027 GetClientRect(hToolbar, &rc); \
1028 /*check_rect("client", rc, res->rcClient);*/ \
1029 buttonCount = SendMessageA(hToolbar, TB_BUTTONCOUNT, 0, 0); \
1030 compare(buttonCount, res->nButtons, "%d"); \
1031 for (i=0; i<min(buttonCount, res->nButtons); i++) { \
1032 ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \
1033 if (broken(tbsize_alt_numtests < sizeof(tbsize_alt_results)/sizeof(tbsize_alt_results[0]) && \
1034 memcmp(&rc, &tbsize_alt_results[tbsize_alt_numtests].rcButton, sizeof(RECT)) == 0)) { \
1035 win_skip("Alternate rect found\n"); \
1036 tbsize_alt_numtests++; \
1037 } else if (!(mask&1)) { \
1038 check_rect("button = %d, tbsize_numtests = %d", rc, res->prcButtons[i], i, tbsize_numtests); \
1039 } else {\
1040 todo_wine { check_rect("button = %d, tbsize_numtests = %d", rc, res->prcButtons[i], i, tbsize_numtests); } \
1041 } \
1042 mask >>= 1; \
1043 } \
1044 tbsize_numtests++; \
1045 }
1046
1047 #define check_sizes() check_sizes_todo(0)
1048
1049 #endif
1050
1051 static TBBUTTON buttons1[] = {
1052 {0, 10, TBSTATE_WRAP|TBSTATE_ENABLED, 0, {0, }, 0, -1},
1053 {0, 11, 0, 0, {0, }, 0, -1},
1054 };
1055 static TBBUTTON buttons2[] = {
1056 {0, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1057 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1058 };
1059 static TBBUTTON buttons3[] = {
1060 {0, 30, TBSTATE_ENABLED, 0, {0, }, 0, 0},
1061 {0, 31, TBSTATE_ENABLED, 0, {0, }, 0, 1},
1062 {0, 32, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, 1},
1063 {0, 33, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, (UINT_PTR)STRING2}
1064 };
1065
1066 static void test_sizes(void)
1067 {
1068 HWND hToolbar = NULL;
1069 HIMAGELIST himl, himl2;
1070 TBBUTTONINFOA tbinfo;
1071 int style;
1072 int i;
1073 int fontheight = system_font_height();
1074
1075 init_tbsize_results();
1076
1077 rebuild_toolbar_with_buttons(&hToolbar);
1078 style = GetWindowLongA(hToolbar, GWL_STYLE);
1079 ok(style == (WS_CHILD|WS_VISIBLE|CCS_TOP), "Invalid style %x\n", style);
1080 check_sizes();
1081 /* the TBSTATE_WRAP makes a second row */
1082 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1083 check_sizes();
1084 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1085 check_sizes();
1086 /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */
1087 SetWindowLongA(hToolbar, GWL_STYLE, style|TBSTYLE_WRAPABLE);
1088 check_sizes();
1089 /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */
1090 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1091 check_sizes();
1092 /* only after adding enough buttons the bar will be wrapped on a
1093 * separator and then on the first button */
1094 for (i=0; i<15; i++)
1095 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1096 check_sizes_todo(0x4);
1097
1098 rebuild_toolbar_with_buttons(&hToolbar);
1099 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1100 /* setting the buttons vertical will only change the window client size */
1101 SetWindowLongA(hToolbar, GWL_STYLE, style | CCS_VERT);
1102 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1103 check_sizes_todo(0x3c);
1104 /* with a TBSTYLE_WRAPABLE a wrapping will occur on the separator */
1105 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_WRAPABLE | CCS_VERT);
1106 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1107 check_sizes_todo(0x7c);
1108
1109 rebuild_toolbar_with_buttons(&hToolbar);
1110 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons1);
1111 /* a TB_SETBITMAPSIZE changes button sizes*/
1112 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
1113 check_sizes();
1114
1115 /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */
1116 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
1117 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1118 check_sizes();
1119 /* but after a TB_SETBITMAPSIZE the top margins is changed */
1120 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20));
1121 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
1122 check_sizes();
1123 /* some vertical toolbar sizes */
1124 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT | TBSTYLE_WRAPABLE | CCS_VERT);
1125 check_sizes_todo(0x7c);
1126
1127 rebuild_toolbar_with_buttons(&hToolbar);
1128 SetWindowLongA(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
1129 /* newly added buttons will be use the previous margin */
1130 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons2);
1131 check_sizes();
1132 /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */
1133 check_button_size(hToolbar, 23, 22);
1134 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n");
1135 check_button_size(hToolbar, 23, 22);
1136 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1137 check_button_size(hToolbar, 23, 100);
1138 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n");
1139 check_button_size(hToolbar, 23, 22);
1140 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1141 check_button_size(hToolbar, 23, 100);
1142 check_sizes();
1143 /* add some buttons with non-default sizes */
1144 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons2);
1145 SendMessageA(hToolbar, TB_INSERTBUTTONA, -1, (LPARAM)&buttons2[0]);
1146 check_sizes();
1147 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[0]);
1148 /* TB_ADDSTRINGA resets the size */
1149 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM) STRING0 "\0" STRING1 "\0");
1150 check_button_size(hToolbar, 23, 23 + fontheight);
1151 check_sizes();
1152 /* TB_SETBUTTONSIZE can be used to crop the text */
1153 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
1154 check_button_size(hToolbar, 23, 22);
1155 check_sizes();
1156 /* the default size is bitmap size + padding */
1157 SendMessageA(hToolbar, TB_SETPADDING, 0, MAKELONG(1, 1));
1158 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
1159 check_button_size(hToolbar, 17, 17);
1160 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(3, 3));
1161 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
1162 check_button_size(hToolbar, 4, 4);
1163
1164 rebuild_toolbar(&hToolbar);
1165 /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */
1166 check_button_size(hToolbar, 23, 22);
1167 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(16, 15));
1168 check_button_size(hToolbar, 23, 21);
1169 /* -1 in TB_SETBITMAPSIZE is a special code meaning that the coordinate shouldn't be changed */
1170 add_128x15_bitmap(hToolbar, 16);
1171 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(14, -1)), "TB_SETBITMAPSIZE failed\n");
1172 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 21), "%x");
1173 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, 12)), "TB_SETBITMAPSIZE failed\n");
1174 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
1175 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, -1)), "TB_SETBITMAPSIZE failed\n");
1176 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
1177 /* check the imagelist */
1178 InvalidateRect(hToolbar, NULL, TRUE);
1179 UpdateWindow(hToolbar);
1180 CHECK_IMAGELIST(16, 14, 12);
1181
1182 rebuild_toolbar(&hToolbar);
1183 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)STRING0 "\0" STRING1 "\0");
1184 /* the height is increased after a TB_ADDSTRINGA */
1185 check_button_size(hToolbar, 23, 23 + fontheight);
1186 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1187 /* if a string is in the pool, even adding a button without a string resets the size */
1188 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons2[0]);
1189 check_button_size(hToolbar, 23, 22);
1190 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1191 /* an BTNS_AUTOSIZE button is also considered when computing the new size */
1192 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[2]);
1193 check_button_size(hToolbar, 7 + string_width(STRING1), 23 + fontheight);
1194 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[0]);
1195 check_sizes();
1196 /* delete button doesn't change the buttons size */
1197 SendMessageA(hToolbar, TB_DELETEBUTTON, 2, 0);
1198 SendMessageA(hToolbar, TB_DELETEBUTTON, 1, 0);
1199 check_button_size(hToolbar, 7 + string_width(STRING1), 23 + fontheight);
1200 /* TB_INSERTBUTTONAS will */
1201 SendMessageA(hToolbar, TB_INSERTBUTTONA, 1, (LPARAM)&buttons2[0]);
1202 check_button_size(hToolbar, 23, 22);
1203
1204 /* TB_HIDEBUTTON and TB_MOVEBUTTON doesn't force a recalc */
1205 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1206 ok(SendMessageA(hToolbar, TB_MOVEBUTTON, 0, 1), "TB_MOVEBUTTON failed\n");
1207 check_button_size(hToolbar, 100, 100);
1208 ok(SendMessageA(hToolbar, TB_HIDEBUTTON, 20, TRUE), "TB_HIDEBUTTON failed\n");
1209 check_button_size(hToolbar, 100, 100);
1210 /* however changing the hidden flag with TB_SETSTATE does */
1211 ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED|TBSTATE_HIDDEN), "TB_SETSTATE failed\n");
1212 check_button_size(hToolbar, 100, 100);
1213 ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED), "TB_SETSTATE failed\n");
1214 check_button_size(hToolbar, 23, 22);
1215
1216 /* TB_SETIMAGELIST always changes the height but the width only if necessary */
1217 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1218 himl = ImageList_LoadImageA(GetModuleHandleA(NULL), (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP_80x15),
1219 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
1220 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
1221 check_button_size(hToolbar, 100, 21);
1222 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1223 check_button_size(hToolbar, 100, 100);
1224 /* But there are no update when we change imagelist, and image sizes are the same */
1225 himl2 = ImageList_LoadImageA(GetModuleHandleA(NULL), (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP_128x15),
1226 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
1227 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LRESULT)himl2) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
1228 check_button_size(hToolbar, 100, 100);
1229 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
1230 check_button_size(hToolbar, 27, 21);
1231 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl2, "TB_SETIMAGELIST failed\n");
1232 check_button_size(hToolbar, 27, 7);
1233 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
1234 check_button_size(hToolbar, 8, 7)
1235 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
1236 check_button_size(hToolbar, 27, 21)
1237 /* the text is taken into account */
1238 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)STRING0 "\0" STRING1 "\0");
1239 SendMessageA(hToolbar, TB_ADDBUTTONSA, 4, (LPARAM)buttons3);
1240 check_button_size(hToolbar, 7 + string_width(STRING1), 22 + fontheight);
1241 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
1242 check_button_size(hToolbar, 7 + string_width(STRING1), 8 + fontheight);
1243 /* the style change also comes into effect */
1244 check_sizes();
1245 SetWindowLongA(hToolbar, GWL_STYLE, GetWindowLongA(hToolbar, GWL_STYLE) | TBSTYLE_FLAT);
1246 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
1247 check_sizes_todo(0x30); /* some small problems with BTNS_AUTOSIZE button sizes */
1248
1249 rebuild_toolbar(&hToolbar);
1250 ImageList_Destroy(himl);
1251 ImageList_Destroy(himl2);
1252
1253 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]);
1254 check_button_size(hToolbar, 7 + string_width(STRING2), 23 + fontheight);
1255 SendMessageA(hToolbar, TB_DELETEBUTTON, 0, 0);
1256 check_button_size(hToolbar, 7 + string_width(STRING2), 23 + fontheight);
1257
1258 rebuild_toolbar(&hToolbar);
1259
1260 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1261 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1262 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons2[0]) == 1, "TB_ADDBUTTONSA failed\n");
1263 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[2]) == 1, "TB_ADDBUTTONSA failed\n");
1264 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[0]) == 1, "TB_ADDBUTTONSA failed\n");
1265 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1266 check_sizes();
1267
1268 rebuild_toolbar(&hToolbar);
1269 SetWindowLongA(hToolbar, GWL_STYLE, TBSTYLE_LIST | GetWindowLongA(hToolbar, GWL_STYLE));
1270 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1271 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1272 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons2[0]) == 1, "TB_ADDBUTTONSA failed\n");
1273 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[2]) == 1, "TB_ADDBUTTONSA failed\n");
1274 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONSA failed\n");
1275 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1276 check_sizes_todo(0xff);
1277
1278 rebuild_toolbar(&hToolbar);
1279 SetWindowLongA(hToolbar, GWL_STYLE, TBSTYLE_LIST | GetWindowLongA(hToolbar, GWL_STYLE));
1280 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1281 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1282 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONSA failed\n");
1283 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1284 check_sizes();
1285
1286 rebuild_toolbar(&hToolbar);
1287 SetWindowLongA(hToolbar, GWL_STYLE, TBSTYLE_WRAPABLE | GetWindowLongA(hToolbar, GWL_STYLE));
1288 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONSA failed\n");
1289 ok(SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONSA failed\n");
1290 tbinfo.cx = 672;
1291 tbinfo.cbSize = sizeof(TBBUTTONINFOA);
1292 tbinfo.dwMask = TBIF_SIZE | TBIF_BYINDEX;
1293 if (SendMessageA(hToolbar, TB_SETBUTTONINFOA, 0, (LPARAM)&tbinfo))
1294 {
1295 ok(SendMessageA(hToolbar, TB_SETBUTTONINFOA, 1, (LPARAM)&tbinfo) != 0, "TB_SETBUTTONINFOA failed\n");
1296 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1297 check_sizes();
1298 }
1299 else /* TBIF_BYINDEX probably not supported, confirm that this was the reason for the failure */
1300 {
1301 tbinfo.dwMask = TBIF_SIZE;
1302 ok(SendMessageA(hToolbar, TB_SETBUTTONINFOA, 33, (LPARAM)&tbinfo) != 0, "TB_SETBUTTONINFOA failed\n");
1303 }
1304
1305 free_tbsize_results();
1306 DestroyWindow(hToolbar);
1307 }
1308
1309 /* Toolbar control has two ways of reacting to a change. We call them a
1310 * relayout and recalc. A recalc forces a recompute of values like button size
1311 * and top margin (the latter in comctl32 <v6), while a relayout uses the cached
1312 * values. This functions creates a flat toolbar with a top margin of a non-flat
1313 * toolbar. We will notice a recalc, as it will recompte the top margin and
1314 * change it to zero*/
1315 static void prepare_recalc_test(HWND *phToolbar)
1316 {
1317 RECT rect;
1318 rebuild_toolbar_with_buttons(phToolbar);
1319 SetWindowLongA(*phToolbar, GWL_STYLE,
1320 GetWindowLongA(*phToolbar, GWL_STYLE) | TBSTYLE_FLAT);
1321 SendMessageA(*phToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1322 ok(rect.top == 2, "Test will make no sense because initial top is %d instead of 2\n",
1323 rect.top);
1324 }
1325
1326 static BOOL did_recalc(HWND hToolbar)
1327 {
1328 RECT rect;
1329 SendMessageA(hToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1330 ok(rect.top == 2 || rect.top == 0, "Unexpected top margin %d in recalc test\n",
1331 rect.top);
1332 return (rect.top == 0);
1333 }
1334
1335 /* call after a recalc did happen to return to an unstable state */
1336 static void restore_recalc_state(HWND hToolbar)
1337 {
1338 RECT rect;
1339 /* return to style with a 2px top margin */
1340 SetWindowLongA(hToolbar, GWL_STYLE,
1341 GetWindowLongA(hToolbar, GWL_STYLE) & ~TBSTYLE_FLAT);
1342 /* recalc */
1343 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&buttons3[3]);
1344 /* top margin will be 0px if a recalc occurs */
1345 SetWindowLongA(hToolbar, GWL_STYLE,
1346 GetWindowLongA(hToolbar, GWL_STYLE) | TBSTYLE_FLAT);
1347 /* safety check */
1348 SendMessageA(hToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1349 ok(rect.top == 2, "Test will make no sense because initial top is %d instead of 2\n",
1350 rect.top);
1351 }
1352
1353 static void test_recalc(void)
1354 {
1355 HWND hToolbar = NULL;
1356 TBBUTTONINFOA bi;
1357 CHAR test[] = "Test";
1358 const int EX_STYLES_COUNT = 5;
1359 int i;
1360 BOOL recalc;
1361
1362 /* Like TB_ADDBUTTONSA tested in test_sized, inserting a button without text
1363 * results in a relayout, while adding one with text forces a recalc */
1364 prepare_recalc_test(&hToolbar);
1365 SendMessageA(hToolbar, TB_INSERTBUTTONA, 1, (LPARAM)&buttons3[0]);
1366 recalc = did_recalc(hToolbar);
1367 ok(!recalc, "Unexpected recalc - adding button without text\n");
1368
1369 prepare_recalc_test(&hToolbar);
1370 SendMessageA(hToolbar, TB_INSERTBUTTONA, 1, (LPARAM)&buttons3[3]);
1371 recalc = did_recalc(hToolbar);
1372 ok(recalc, "Expected a recalc - adding button with text\n");
1373
1374 /* TB_SETBUTTONINFOA, even when adding a text, results only in a relayout */
1375 prepare_recalc_test(&hToolbar);
1376 bi.cbSize = sizeof(bi);
1377 bi.dwMask = TBIF_TEXT;
1378 bi.pszText = test;
1379 SendMessageA(hToolbar, TB_SETBUTTONINFOA, 1, (LPARAM)&bi);
1380 recalc = did_recalc(hToolbar);
1381 ok(!recalc, "Unexpected recalc - setting a button text\n");
1382
1383 /* most extended styled doesn't force a recalc (testing all the bits gives
1384 * the same results, but prints some ERRs while testing) */
1385 for (i = 0; i < EX_STYLES_COUNT; i++)
1386 {
1387 if (i == 1 || i == 3) /* an undoc style and TBSTYLE_EX_MIXEDBUTTONS */
1388 continue;
1389 prepare_recalc_test(&hToolbar);
1390 expect(0, (int)SendMessageA(hToolbar, TB_GETEXTENDEDSTYLE, 0, 0));
1391 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, (1 << i));
1392 recalc = did_recalc(hToolbar);
1393 ok(!recalc, "Unexpected recalc - setting bit %d\n", i);
1394 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, 0);
1395 recalc = did_recalc(hToolbar);
1396 ok(!recalc, "Unexpected recalc - clearing bit %d\n", i);
1397 expect(0, (int)SendMessageA(hToolbar, TB_GETEXTENDEDSTYLE, 0, 0));
1398 }
1399
1400 /* TBSTYLE_EX_MIXEDBUTTONS does a recalc on change */
1401 prepare_recalc_test(&hToolbar);
1402 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1403 recalc = did_recalc(hToolbar);
1404 if (recalc)
1405 {
1406 ok(recalc, "Expected a recalc - setting TBSTYLE_EX_MIXEDBUTTONS\n");
1407 restore_recalc_state(hToolbar);
1408 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1409 recalc = did_recalc(hToolbar);
1410 ok(!recalc, "Unexpected recalc - setting TBSTYLE_EX_MIXEDBUTTONS again\n");
1411 restore_recalc_state(hToolbar);
1412 SendMessageA(hToolbar, TB_SETEXTENDEDSTYLE, 0, 0);
1413 recalc = did_recalc(hToolbar);
1414 ok(recalc, "Expected a recalc - clearing TBSTYLE_EX_MIXEDBUTTONS\n");
1415 }
1416 else win_skip( "No recalc on TBSTYLE_EX_MIXEDBUTTONS\n" );
1417
1418 /* undocumented exstyle 0x2 seems to change the top margin, which
1419 * interferes with these tests */
1420
1421 DestroyWindow(hToolbar);
1422 }
1423
1424 static void test_getbuttoninfo(void)
1425 {
1426 HWND hToolbar = NULL;
1427 int i;
1428
1429 rebuild_toolbar_with_buttons(&hToolbar);
1430 for (i = 0; i < 128; i++)
1431 {
1432 TBBUTTONINFOA tbi;
1433 int ret;
1434
1435 tbi.cbSize = i;
1436 tbi.dwMask = TBIF_COMMAND;
1437 ret = (int)SendMessageA(hToolbar, TB_GETBUTTONINFOA, 1, (LPARAM)&tbi);
1438 if (i == sizeof(TBBUTTONINFOA)) {
1439 compare(ret, 0, "%d");
1440 } else {
1441 compare(ret, -1, "%d");
1442 }
1443 }
1444 DestroyWindow(hToolbar);
1445 }
1446
1447 static void test_createtoolbarex(void)
1448 {
1449 HWND hToolbar;
1450 TBBUTTON btns[3];
1451 ZeroMemory(&btns, sizeof(btns));
1452
1453 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1454 3, 20, 20, 16, 16, sizeof(TBBUTTON));
1455 CHECK_IMAGELIST(16, 20, 20);
1456 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x1a001b, "%x");
1457 DestroyWindow(hToolbar);
1458
1459 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1460 3, 4, 4, 16, 16, sizeof(TBBUTTON));
1461 CHECK_IMAGELIST(32, 4, 4);
1462 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xa000b, "%x");
1463 DestroyWindow(hToolbar);
1464
1465 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1466 3, 0, 8, 12, 12, sizeof(TBBUTTON));
1467 CHECK_IMAGELIST(16, 12, 12);
1468 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x120013, "%x");
1469 DestroyWindow(hToolbar);
1470
1471 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1472 3, -1, 8, 12, 12, sizeof(TBBUTTON));
1473 CHECK_IMAGELIST(16, 12, 8);
1474 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0013, "%x");
1475 DestroyWindow(hToolbar);
1476
1477 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1478 3, -1, 8, -1, 12, sizeof(TBBUTTON));
1479 CHECK_IMAGELIST(16, 16, 8);
1480 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0017, "%x");
1481 DestroyWindow(hToolbar);
1482
1483 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1484 3, 0, 0, 12, -1, sizeof(TBBUTTON));
1485 CHECK_IMAGELIST(16, 12, 16);
1486 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x160013, "%x");
1487 DestroyWindow(hToolbar);
1488
1489 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandleA(NULL), IDB_BITMAP_128x15, btns,
1490 3, 0, 0, 0, 12, sizeof(TBBUTTON));
1491 CHECK_IMAGELIST(16, 16, 16);
1492 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x160017, "%x");
1493 DestroyWindow(hToolbar);
1494 }
1495
1496 static void test_dispinfo(void)
1497 {
1498 HWND hToolbar = NULL;
1499 const TBBUTTON buttons_disp[] = {
1500 {-1, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1501 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1502 };
1503 BOOL ret;
1504
1505 rebuild_toolbar(&hToolbar);
1506 SendMessageA(hToolbar, TB_LOADIMAGES, IDB_HIST_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
1507 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons_disp);
1508 g_dwExpectedDispInfoMask = TBNF_IMAGE;
1509 /* Some TBN_GETDISPINFO tests will be done in MyWnd_Notify function.
1510 * We will receive TBN_GETDISPINFOW even if the control is ANSI */
1511 compare((BOOL)SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 0, "%d");
1512 ShowWindow(hToolbar, SW_SHOW);
1513 UpdateWindow(hToolbar);
1514
1515 ret = (BOOL)SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, TRUE, 0);
1516 compare(ret, FALSE, "%d");
1517 compare(SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 1L, "%ld");
1518 InvalidateRect(hToolbar, NULL, FALSE);
1519 UpdateWindow(hToolbar);
1520
1521 ret = (BOOL)SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, FALSE, 0);
1522 compare(ret, TRUE, "%d");
1523 compare(SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 0L, "%ld");
1524 InvalidateRect(hToolbar, NULL, FALSE);
1525 UpdateWindow(hToolbar);
1526
1527 DestroyWindow(hToolbar);
1528 g_dwExpectedDispInfoMask = 0;
1529 }
1530
1531 typedef struct
1532 {
1533 int nRows;
1534 BOOL bLarger;
1535 int expectedRows;
1536 } tbrows_result_t;
1537
1538 static tbrows_result_t tbrows_results[] =
1539 {
1540 {1, TRUE, 1}, /* 0: Simple case 9 in a row */
1541 {2, TRUE, 2}, /* 1: Another simple case 5 on one row, 4 on another*/
1542 {3, FALSE, 3}, /* 2: 3 lines - should be 3 lines of 3 buttons */
1543 {8, FALSE, 5}, /* 3: 8 lines - should be 5 lines of 2 buttons */
1544 {8, TRUE, 9}, /* 4: 8 lines but grow - should be 9 lines */
1545 {1, TRUE, 1} /* 5: Back to simple case */
1546 };
1547
1548 static void test_setrows(void)
1549 {
1550 TBBUTTON buttons[9];
1551 HWND hToolbar;
1552 DWORD i;
1553
1554 for (i=0; i<9; i++)
1555 MakeButton(buttons+i, 1000+i, TBSTYLE_FLAT | TBSTYLE_CHECKGROUP, 0);
1556
1557 /* Test 1 - 9 buttons */
1558 hToolbar = CreateToolbarEx(hMainWnd,
1559 WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD | CCS_NORESIZE | CCS_NOPARENTALIGN
1560 | CCS_NOMOVEY | CCS_TOP,
1561 0,
1562 0, NULL, 0,
1563 buttons, sizeof(buttons)/sizeof(buttons[0]),
1564 20, 20, 0, 0, sizeof(TBBUTTON));
1565 ok(hToolbar != NULL, "Toolbar creation\n");
1566 ok(SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
1567
1568 /* test setting rows to each of 1-10 with bLarger true and false */
1569 for (i=0; i<(sizeof(tbrows_results) / sizeof(tbrows_result_t)); i++) {
1570 RECT rc;
1571 int rows;
1572
1573 memset(&rc, 0xCC, sizeof(rc));
1574 SendMessageA(hToolbar, TB_SETROWS,
1575 MAKELONG(tbrows_results[i].nRows, tbrows_results[i].bLarger),
1576 (LPARAM) &rc);
1577
1578 rows = SendMessageA(hToolbar, TB_GETROWS, MAKELONG(0,0), MAKELONG(0,0));
1579 ok(rows == tbrows_results[i].expectedRows,
1580 "[%d] Unexpected number of rows %d (expected %d)\n", i, rows,
1581 tbrows_results[i].expectedRows);
1582 }
1583
1584 DestroyWindow(hToolbar);
1585 }
1586
1587 static void test_getstring(void)
1588 {
1589 HWND hToolbar = NULL;
1590 char str[10];
1591 WCHAR strW[10];
1592 static const char answer[] = "STR";
1593 static const WCHAR answerW[] = { 'S','T','R',0 };
1594 INT r;
1595
1596 hToolbar = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
1597 ok(hToolbar != NULL, "Toolbar creation problem\n");
1598
1599 r = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(0, 0), 0);
1600 if (r == 0)
1601 {
1602 win_skip("TB_GETSTRINGA and TB_GETSTRINGW need 5.80\n");
1603 DestroyWindow(hToolbar);
1604 return;
1605 }
1606 expect(-1, r);
1607 r = SendMessageW(hToolbar, TB_GETSTRINGW, MAKEWPARAM(0, 0), 0);
1608 expect(-1, r);
1609 r = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)answer);
1610 expect(0, r);
1611 r = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(0, 0), 0);
1612 expect(lstrlenA(answer), r);
1613 r = SendMessageW(hToolbar, TB_GETSTRINGW, MAKEWPARAM(0, 0), 0);
1614 expect(lstrlenA(answer), r);
1615 r = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(sizeof(str), 0), (LPARAM)str);
1616 expect(lstrlenA(answer), r);
1617 expect(0, lstrcmpA(answer, str));
1618 r = SendMessageW(hToolbar, TB_GETSTRINGW, MAKEWPARAM(sizeof(strW), 0), (LPARAM)strW);
1619 expect(lstrlenA(answer), r);
1620 expect(0, lstrcmpW(answerW, strW));
1621
1622 DestroyWindow(hToolbar);
1623 }
1624
1625 static void test_tooltip(void)
1626 {
1627 HWND hToolbar = NULL;
1628 const TBBUTTON buttons_disp[] = {
1629 {-1, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1630 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1631 };
1632 NMTTDISPINFOW nmtti;
1633 HWND tooltip;
1634
1635 rebuild_toolbar(&hToolbar);
1636
1637 SendMessageA(hToolbar, TB_ADDBUTTONSA, 2, (LPARAM)buttons_disp);
1638
1639 /* W used to get through toolbar code that assumes tooltip is always Unicode */
1640 memset(&nmtti, 0, sizeof(nmtti));
1641 nmtti.hdr.code = TTN_GETDISPINFOW;
1642 nmtti.hdr.idFrom = 20;
1643
1644 SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, FALSE, 0);
1645
1646 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1647 SendMessageA(hToolbar, WM_NOTIFY, 0, (LPARAM)&nmtti);
1648 ok_sequence(sequences, PARENT_SEQ_INDEX, ttgetdispinfo_parent_seq,
1649 "dispinfo from tooltip", TRUE);
1650
1651 g_ResetDispTextPtr = TRUE;
1652 SendMessageA(hToolbar, WM_NOTIFY, 0, (LPARAM)&nmtti);
1653 g_ResetDispTextPtr = FALSE;
1654
1655 DestroyWindow(hToolbar);
1656
1657 /* TBSTYLE_TOOLTIPS */
1658 hToolbar = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
1659 hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
1660 tooltip = (HWND)SendMessageA(hToolbar, TB_GETTOOLTIPS, 0, 0);
1661 ok(tooltip == NULL, "got %p\n", tooltip);
1662 DestroyWindow(hToolbar);
1663 }
1664
1665 static void test_get_set_style(void)
1666 {
1667 TBBUTTON buttons[9];
1668 DWORD style, style2, ret;
1669 HWND hToolbar;
1670 int i;
1671
1672 for (i=0; i<9; i++)
1673 MakeButton(buttons+i, 1000+i, TBSTYLE_CHECKGROUP, 0);
1674 MakeButton(buttons+3, 1003, TBSTYLE_SEP|TBSTYLE_GROUP, 0);
1675 MakeButton(buttons+6, 1006, TBSTYLE_SEP, 0);
1676
1677 hToolbar = CreateToolbarEx(hMainWnd,
1678 WS_VISIBLE | WS_CLIPCHILDREN | CCS_TOP |
1679 WS_CHILD | TBSTYLE_LIST,
1680 100,
1681 0, NULL, 0,
1682 buttons, sizeof(buttons)/sizeof(buttons[0]),
1683 0, 0, 20, 16, sizeof(TBBUTTON));
1684 ok(hToolbar != NULL, "Toolbar creation\n");
1685 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"test\000");
1686
1687 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
1688 style2 = GetWindowLongA(hToolbar, GWL_STYLE);
1689 todo_wine
1690 ok(style == style2, "got 0x%08x, expected 0x%08x\n", style, style2);
1691
1692 /* try to alter common window bits */
1693 style2 |= WS_BORDER;
1694 ret = SendMessageA(hToolbar, TB_SETSTYLE, 0, style2);
1695 ok(ret == 0, "got %d\n", ret);
1696 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
1697 style2 = GetWindowLongA(hToolbar, GWL_STYLE);
1698 ok((style != style2) && (style == (style2 | WS_BORDER)),
1699 "got 0x%08x, expected 0x%08x\n", style, style2);
1700 ok(style & WS_BORDER, "got 0x%08x\n", style);
1701
1702 /* now styles are the same, alter window style */
1703 ret = SendMessageA(hToolbar, TB_SETSTYLE, 0, style2);
1704 ok(ret == 0, "got %d\n", ret);
1705 style2 |= WS_BORDER;
1706 SetWindowLongA(hToolbar, GWL_STYLE, style2);
1707 style = SendMessageA(hToolbar, TB_GETSTYLE, 0, 0);
1708 ok(style == style2, "got 0x%08x, expected 0x%08x\n", style, style2);
1709
1710 DestroyWindow(hToolbar);
1711 }
1712
1713 static HHOOK g_tbhook;
1714 static HWND g_toolbar;
1715
1716 DEFINE_EXPECT(g_hook_create);
1717 DEFINE_EXPECT(g_hook_WM_NCCREATE);
1718 DEFINE_EXPECT(g_hook_WM_CREATE);
1719
1720 static LRESULT WINAPI toolbar_subclass_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1721 {
1722 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
1723 LRESULT ret;
1724 DWORD style;
1725
1726 if (msg == WM_NCCREATE)
1727 {
1728 if (g_toolbar == hwnd)
1729 {
1730 CHECK_EXPECT2(g_hook_WM_NCCREATE);
1731 g_toolbar = hwnd;
1732 ret = CallWindowProcA(oldproc, hwnd, msg, wParam, lParam);
1733
1734 /* control is already set up */
1735 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
1736 ok(style != 0, "got %x\n", style);
1737
1738 style = GetWindowLongA(hwnd, GWL_STYLE);
1739 ok((style & TBSTYLE_TOOLTIPS) == 0, "got 0x%08x\n", style);
1740 SetWindowLongA(hwnd, GWL_STYLE, style|TBSTYLE_TOOLTIPS);
1741 style = GetWindowLongA(hwnd, GWL_STYLE);
1742 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%08x\n", style);
1743
1744 return ret;
1745 }
1746 }
1747 else if (msg == WM_CREATE)
1748 {
1749 CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
1750
1751 if (g_toolbar == hwnd)
1752 {
1753 CHECK_EXPECT2(g_hook_WM_CREATE);
1754
1755 style = GetWindowLongA(hwnd, GWL_STYLE);
1756 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%08x\n", style);
1757
1758 /* test if toolbar-specific messages are already working before WM_CREATE */
1759 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
1760 ok(style != 0, "got %x\n", style);
1761 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%x\n", style);
1762 ok((cs->style & TBSTYLE_TOOLTIPS) == 0, "0x%08x\n", cs->style);
1763
1764 ret = CallWindowProcA(oldproc, hwnd, msg, wParam, lParam);
1765
1766 style = GetWindowLongA(hwnd, GWL_STYLE);
1767 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%08x\n", style);
1768
1769 /* test if toolbar-specific messages are already working before WM_CREATE */
1770 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
1771 ok(style != 0, "got %x\n", style);
1772 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%x\n", style);
1773
1774 return ret;
1775 }
1776 }
1777
1778 return CallWindowProcA(oldproc, hwnd, msg, wParam, lParam);
1779 }
1780
1781 static LRESULT CALLBACK cbt_hook_proc(int code, WPARAM wParam, LPARAM lParam)
1782 {
1783 if (code == HCBT_CREATEWND)
1784 {
1785 HWND hwnd = (HWND)wParam;
1786
1787 if (!g_toolbar)
1788 {
1789 WNDPROC oldproc;
1790
1791 CHECK_EXPECT2(g_hook_create);
1792 g_toolbar = hwnd;
1793 /* subclass */
1794 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)toolbar_subclass_proc);
1795 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
1796 }
1797 return 0;
1798 }
1799
1800 return CallNextHookEx(g_tbhook, code, wParam, lParam);
1801 }
1802
1803 static void test_create(void)
1804 {
1805 HWND hwnd, tooltip;
1806 DWORD style;
1807
1808 g_tbhook = SetWindowsHookA(WH_CBT, cbt_hook_proc);
1809
1810 SET_EXPECT(g_hook_create);
1811 SET_EXPECT(g_hook_WM_NCCREATE);
1812 SET_EXPECT(g_hook_WM_CREATE);
1813
1814 hwnd = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
1815 hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
1816
1817 CHECK_CALLED(g_hook_create);
1818 CHECK_CALLED(g_hook_WM_NCCREATE);
1819 CHECK_CALLED(g_hook_WM_CREATE);
1820
1821 style = GetWindowLongA(hwnd, GWL_STYLE);
1822 ok((style & TBSTYLE_TOOLTIPS) == TBSTYLE_TOOLTIPS, "got 0x%08x\n", style);
1823
1824 tooltip = (HWND)SendMessageA(hwnd, TB_GETTOOLTIPS, 0, 0);
1825 ok(tooltip != NULL, "got %p\n", tooltip);
1826 ok(GetParent(tooltip) == hMainWnd, "got %p, %p\n", hMainWnd, hwnd);
1827
1828 DestroyWindow(hwnd);
1829 UnhookWindowsHook(WH_CBT, cbt_hook_proc);
1830
1831 /* TBSTYLE_TRANSPARENT */
1832 hwnd = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL,
1833 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|TBSTYLE_FLAT|TBSTYLE_TOOLTIPS|TBSTYLE_GROUP,
1834 0, 0, 0, 0, hMainWnd, (HMENU)5, GetModuleHandleA(NULL), NULL);
1835
1836 style = GetWindowLongA(hwnd, GWL_STYLE);
1837 ok((style & TBSTYLE_TRANSPARENT) == TBSTYLE_TRANSPARENT, "got 0x%08x\n", style);
1838
1839 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
1840 ok((style & TBSTYLE_TRANSPARENT) == TBSTYLE_TRANSPARENT, "got 0x%08x\n", style);
1841
1842 DestroyWindow(hwnd);
1843 }
1844
1845 typedef struct {
1846 DWORD mask;
1847 DWORD style;
1848 DWORD style_set;
1849 } extended_style_t;
1850
1851 static const extended_style_t extended_style_test[] = {
1852 {
1853 TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER,
1854 TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER,
1855 TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER
1856 },
1857 {
1858 TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS,
1859 TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS
1860 },
1861
1862 { 0, TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS },
1863 { 0, 0, 0 },
1864 { 0, TBSTYLE_EX_DRAWDDARROWS, TBSTYLE_EX_DRAWDDARROWS },
1865 { 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS, TBSTYLE_EX_HIDECLIPPEDBUTTONS },
1866
1867 { 0, 0, 0 },
1868 { TBSTYLE_EX_HIDECLIPPEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS, 0 },
1869 { TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_HIDECLIPPEDBUTTONS, 0 },
1870 { TBSTYLE_EX_DOUBLEBUFFER, TBSTYLE_EX_MIXEDBUTTONS, 0 },
1871
1872 {
1873 TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS,
1874 TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS
1875 },
1876 {
1877 TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS,
1878 TBSTYLE_EX_DOUBLEBUFFER, TBSTYLE_EX_DOUBLEBUFFER
1879 }
1880 };
1881
1882 static void test_TB_GET_SET_EXTENDEDSTYLE(void)
1883 {
1884 DWORD style, oldstyle, oldstyle2;
1885 const extended_style_t *ptr;
1886 HWND hwnd = NULL;
1887 int i;
1888
1889 rebuild_toolbar(&hwnd);
1890
1891 SendMessageA(hwnd, TB_SETEXTENDEDSTYLE, TBSTYLE_EX_DOUBLEBUFFER, TBSTYLE_EX_MIXEDBUTTONS);
1892 style = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
1893 if (style == TBSTYLE_EX_MIXEDBUTTONS)
1894 {
1895 win_skip("Some extended style bits are not supported\n");
1896 DestroyWindow(hwnd);
1897 return;
1898 }
1899
1900 for (i = 0; i < sizeof(extended_style_test)/sizeof(extended_style_t); i++)
1901 {
1902 ptr = &extended_style_test[i];
1903
1904 oldstyle2 = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
1905
1906 oldstyle = SendMessageA(hwnd, TB_SETEXTENDEDSTYLE, ptr->mask, ptr->style);
1907 ok(oldstyle == oldstyle2, "%d: got old style 0x%08x, expected 0x%08x\n", i, oldstyle, oldstyle2);
1908 style = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
1909 ok(style == ptr->style_set, "%d: got style 0x%08x, expected 0x%08x\n", i, style, ptr->style_set);
1910 }
1911
1912 /* Windows sets CCS_VERT when TB_GETEXTENDEDSTYLE is set */
1913 oldstyle2 = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
1914 oldstyle = SendMessageA(hwnd, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_VERTICAL);
1915 ok(oldstyle == oldstyle2, "got old style 0x%08x, expected 0x%08x\n", oldstyle, oldstyle2);
1916 style = SendMessageA(hwnd, TB_GETEXTENDEDSTYLE, 0, 0);
1917 ok(style == TBSTYLE_EX_VERTICAL, "got style 0x%08x, expected 0x%08x\n", style, TBSTYLE_EX_VERTICAL);
1918 style = SendMessageA(hwnd, TB_GETSTYLE, 0, 0);
1919 todo_wine
1920 ok(style == CCS_VERT, "got style 0x%08x, expected 0x%08x\n", style, CCS_VERT);
1921
1922 DestroyWindow(hwnd);
1923 }
1924
1925 START_TEST(toolbar)
1926 {
1927 WNDCLASSA wc;
1928 MSG msg;
1929 RECT rc;
1930
1931 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1932
1933 InitCommonControls();
1934
1935 wc.style = CS_HREDRAW | CS_VREDRAW;
1936 wc.cbClsExtra = 0;
1937 wc.cbWndExtra = 0;
1938 wc.hInstance = GetModuleHandleA(NULL);
1939 wc.hIcon = NULL;
1940 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_IBEAM);
1941 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1942 wc.lpszMenuName = NULL;
1943 wc.lpszClassName = "Toolbar test parent";
1944 wc.lpfnWndProc = parent_wnd_proc;
1945 RegisterClassA(&wc);
1946
1947 hMainWnd = CreateWindowExA(0, "Toolbar test parent", "Blah", WS_OVERLAPPEDWINDOW,
1948 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
1949 GetClientRect(hMainWnd, &rc);
1950 ShowWindow(hMainWnd, SW_SHOW);
1951
1952 basic_test();
1953 test_add_bitmap();
1954 test_add_string();
1955 test_hotitem();
1956 test_sizes();
1957 test_recalc();
1958 test_getbuttoninfo();
1959 test_createtoolbarex();
1960 test_dispinfo();
1961 test_setrows();
1962 test_getstring();
1963 test_tooltip();
1964 test_get_set_style();
1965 test_create();
1966 test_TB_GET_SET_EXTENDEDSTYLE();
1967
1968 PostQuitMessage(0);
1969 while(GetMessageA(&msg,0,0,0)) {
1970 TranslateMessage(&msg);
1971 DispatchMessageA(&msg);
1972 }
1973 DestroyWindow(hMainWnd);
1974 }