1 /* Unit tests for treeview.
3 * Copyright 2005 Krzysztof Foltman
4 * Copyright 2007 Mikolaj Zalewski
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "resources.h"
34 #include "wine/test.h"
37 static BOOL g_fBlockHotItemChange;
38 static BOOL g_fReceivedHotItemChange;
39 static BOOL g_fExpectedHotItemOld;
40 static BOOL g_fExpectedHotItemNew;
41 static DWORD g_dwExpectedDispInfoMask;
43 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
45 #define check_rect(name, val, exp) ok(val.top == exp.top && val.bottom == exp.bottom && \
46 val.left == exp.left && val.right == exp.right, "invalid rect (" name ") (%d,%d) (%d,%d) - expected (%d,%d) (%d,%d)\n", \
47 val.left, val.top, val.right, val.bottom, exp.left, exp.top, exp.right, exp.bottom);
49 #define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp));
51 static void MakeButton(TBBUTTON *p, int idCommand, int fsStyle, int nString) {
53 p->idCommand = idCommand;
54 p->fsState = TBSTATE_ENABLED;
59 static LRESULT MyWnd_Notify(LPARAM lParam)
61 NMHDR *hdr = (NMHDR *)lParam;
66 case TBN_HOTITEMCHANGE:
67 nmhi = (NMTBHOTITEM *)lParam;
68 g_fReceivedHotItemChange = TRUE;
69 if (g_fExpectedHotItemOld != g_fExpectedHotItemNew)
71 compare(nmhi->idOld, g_fExpectedHotItemOld, "%d");
72 compare(nmhi->idNew, g_fExpectedHotItemNew, "%d");
74 if (g_fBlockHotItemChange)
78 case TBN_GETDISPINFOA:
79 ok(FALSE, "TBN_GETDISPINFOA received\n");
82 case TBN_GETDISPINFOW:
83 nmdisp = (NMTBDISPINFOA *)lParam;
85 compare(nmdisp->dwMask, g_dwExpectedDispInfoMask, "%x");
86 compare(nmdisp->iImage, -1, "%d");
87 ok(nmdisp->pszText == NULL, "pszText is not NULL\n");
93 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
98 return MyWnd_Notify(lParam);
100 return DefWindowProcA(hWnd, msg, wParam, lParam);
103 static void basic_test(void)
109 MakeButton(buttons+i, 1000+i, TBSTYLE_CHECKGROUP, 0);
110 MakeButton(buttons+3, 1003, TBSTYLE_SEP|TBSTYLE_GROUP, 0);
111 MakeButton(buttons+6, 1006, TBSTYLE_SEP, 0);
113 hToolbar = CreateToolbarEx(hMainWnd,
114 WS_VISIBLE | WS_CLIPCHILDREN | CCS_TOP |
115 WS_CHILD | TBSTYLE_LIST,
118 buttons, sizeof(buttons)/sizeof(buttons[0]),
119 0, 0, 20, 16, sizeof(TBBUTTON));
120 ok(hToolbar != NULL, "Toolbar creation\n");
121 SendMessage(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"test\000");
123 /* test for exclusion working inside a separator-separated :-) group */
124 SendMessage(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 */
125 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
126 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1001, 0), "A2 not pressed\n");
128 SendMessage(hToolbar, TB_CHECKBUTTON, 1004, 1); /* press A5, release A1 */
129 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 pressed\n");
130 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 not pressed anymore\n");
132 SendMessage(hToolbar, TB_CHECKBUTTON, 1005, 1); /* press A6, release A5 */
133 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
134 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 not pressed anymore\n");
136 /* test for inter-group crosstalk, ie. two radio groups interfering with each other */
137 SendMessage(hToolbar, TB_CHECKBUTTON, 1007, 1); /* press B2 */
138 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
139 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 still not pressed\n");
140 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 pressed\n");
142 SendMessage(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 and ensure B group didn't suffer */
143 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 not pressed anymore\n");
144 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
145 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 still pressed\n");
147 SendMessage(hToolbar, TB_CHECKBUTTON, 1008, 1); /* press B3, and ensure A group didn't suffer */
148 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
149 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
150 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 not pressed\n");
151 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1008, 0), "B3 pressed\n");
153 /* tests with invalid index */
154 compare(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 0xdeadbeef, 0), -1L, "%ld");
155 compare(SendMessage(hToolbar, TB_ISBUTTONPRESSED, 0xdeadbeef, 0), -1L, "%ld");
156 compare(SendMessage(hToolbar, TB_ISBUTTONENABLED, 0xdeadbeef, 0), -1L, "%ld");
157 compare(SendMessage(hToolbar, TB_ISBUTTONINDETERMINATE, 0xdeadbeef, 0), -1L, "%ld");
158 compare(SendMessage(hToolbar, TB_ISBUTTONHIGHLIGHTED, 0xdeadbeef, 0), -1L, "%ld");
159 compare(SendMessage(hToolbar, TB_ISBUTTONHIDDEN, 0xdeadbeef, 0), -1L, "%ld");
161 DestroyWindow(hToolbar);
164 static void rebuild_toolbar(HWND *hToolbar)
166 if (*hToolbar != NULL)
167 DestroyWindow(*hToolbar);
168 *hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
169 hMainWnd, (HMENU)5, GetModuleHandle(NULL), NULL);
170 ok(*hToolbar != NULL, "Toolbar creation problem\n");
171 ok(SendMessage(*hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n");
172 ok(SendMessage(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
173 ok(SendMessage(*hToolbar, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0)==1, "WM_SETFONT\n");
176 static void rebuild_toolbar_with_buttons(HWND *hToolbar)
179 rebuild_toolbar(hToolbar);
181 ZeroMemory(&buttons, sizeof(buttons));
182 buttons[0].idCommand = 1;
183 buttons[0].fsStyle = BTNS_BUTTON;
184 buttons[0].fsState = TBSTATE_ENABLED;
185 buttons[0].iString = -1;
186 buttons[1].idCommand = 3;
187 buttons[1].fsStyle = BTNS_BUTTON;
188 buttons[1].fsState = TBSTATE_ENABLED;
189 buttons[1].iString = -1;
190 buttons[2].idCommand = 5;
191 buttons[2].fsStyle = BTNS_SEP;
192 buttons[2].fsState = TBSTATE_ENABLED;
193 buttons[2].iString = -1;
194 buttons[3].idCommand = 7;
195 buttons[3].fsStyle = BTNS_BUTTON;
196 buttons[3].fsState = TBSTATE_ENABLED;
197 buttons[3].iString = -1;
198 buttons[4].idCommand = 9;
199 buttons[4].fsStyle = BTNS_BUTTON;
200 buttons[4].fsState = 0; /* disabled */
201 buttons[4].iString = -1;
202 ok(SendMessage(*hToolbar, TB_ADDBUTTONS, 5, (LPARAM)buttons) == 1, "TB_ADDBUTTONS failed\n");
203 ok(SendMessage(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
206 static void add_128x15_bitmap(HWND hToolbar, int nCmds)
209 bmp128.hInst = GetModuleHandle(NULL);
210 bmp128.nID = IDB_BITMAP_128x15;
211 ok(SendMessageA(hToolbar, TB_ADDBITMAP, nCmds, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
214 #define CHECK_IMAGELIST(count, dx, dy) { \
216 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
217 ok(himl != NULL, "No image list\n"); \
219 ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
220 ImageList_GetIconSize(himl, &cx, &cy); \
221 ok(cx == dx && cy == dy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
225 static void test_add_bitmap(void)
227 HWND hToolbar = NULL;
230 TBADDBITMAP stdsmall;
235 /* empty 128x15 bitmap */
236 bmp128.hInst = GetModuleHandle(NULL);
237 bmp128.nID = IDB_BITMAP_128x15;
239 /* empty 80x15 bitmap */
240 bmp80.hInst = GetModuleHandle(NULL);
241 bmp80.nID = IDB_BITMAP_80x15;
243 /* standard bitmap - 240x15 pixels */
244 stdsmall.hInst = HINST_COMMCTRL;
245 stdsmall.nID = IDB_STD_SMALL_COLOR;
247 rebuild_toolbar(&hToolbar);
248 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
249 CHECK_IMAGELIST(8, 16, 16);
251 /* adding more bitmaps */
252 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 8, "TB_ADDBITMAP - unexpected return\n");
253 CHECK_IMAGELIST(13, 16, 16);
254 /* adding the same bitmap will simply return the index of the already loaded block */
255 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128);
256 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
257 CHECK_IMAGELIST(13, 16, 16);
258 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
259 ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
260 CHECK_IMAGELIST(13, 16, 16);
261 /* even if we increase the wParam */
262 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 55, (LPARAM)&bmp80);
263 ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
264 CHECK_IMAGELIST(13, 16, 16);
266 /* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
267 rebuild_toolbar(&hToolbar);
268 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
269 CHECK_IMAGELIST(8, 16, 16);
270 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
271 ok(ret == 3, "TB_ADDBITMAP - unexpected return %d\n", ret);
272 /* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
273 CHECK_IMAGELIST(13, 16, 16);
275 /* the same for negative wParam */
276 rebuild_toolbar(&hToolbar);
277 ret = SendMessageA(hToolbar, TB_ADDBITMAP, -143, (LPARAM)&bmp128);
278 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
279 CHECK_IMAGELIST(8, 16, 16);
280 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
281 ok(ret == -143, "TB_ADDBITMAP - unexpected return %d\n", ret);
282 CHECK_IMAGELIST(13, 16, 16);
284 /* for zero only one bitmap will be added */
285 rebuild_toolbar(&hToolbar);
286 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&bmp80);
287 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
288 CHECK_IMAGELIST(1, 16, 16);
290 /* if wParam is larger than the amount of icons, the list is grown */
291 rebuild_toolbar(&hToolbar);
292 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
293 CHECK_IMAGELIST(100, 16, 16);
294 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128);
295 ok(ret == 100, "TB_ADDBITMAP - unexpected return %d\n", ret);
296 CHECK_IMAGELIST(200, 16, 16);
298 /* adding built-in items - the wParam is ignored */
299 rebuild_toolbar(&hToolbar);
300 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
301 CHECK_IMAGELIST(5, 16, 16);
302 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 5, "TB_ADDBITMAP - unexpected return\n");
303 CHECK_IMAGELIST(20, 16, 16);
304 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 20, "TB_ADDBITMAP - unexpected return\n");
305 CHECK_IMAGELIST(28, 16, 16);
307 /* when we increase the bitmap size, less icons will be created */
308 rebuild_toolbar(&hToolbar);
309 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20)) == TRUE, "TB_SETBITMAPSIZE failed\n");
310 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
311 CHECK_IMAGELIST(6, 20, 20);
312 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
313 ok(ret == 1, "TB_ADDBITMAP - unexpected return %d\n", ret);
314 CHECK_IMAGELIST(10, 20, 20);
315 /* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
316 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
317 UpdateWindow(hToolbar);
318 CHECK_IMAGELIST(26, 8, 8);
319 /* loading a standard bitmaps automatically resizes the icons */
320 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&stdsmall) == 2, "TB_ADDBITMAP - unexpected return\n");
321 UpdateWindow(hToolbar);
322 CHECK_IMAGELIST(28, 16, 16);
324 /* two more SETBITMAPSIZE tests */
325 rebuild_toolbar(&hToolbar);
326 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
327 CHECK_IMAGELIST(100, 16, 16);
328 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 100, "TB_ADDBITMAP - unexpected return\n");
329 CHECK_IMAGELIST(200, 16, 16);
330 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
331 UpdateWindow(hToolbar);
332 CHECK_IMAGELIST(200, 8, 8);
333 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(30, 30)) == TRUE, "TB_SETBITMAPSIZE failed\n");
334 UpdateWindow(hToolbar);
335 CHECK_IMAGELIST(200, 30, 30);
336 rebuild_toolbar(&hToolbar);
337 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
338 CHECK_IMAGELIST(8, 16, 16);
339 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp80) == 5, "TB_ADDBITMAP - unexpected return\n");
340 CHECK_IMAGELIST(13, 16, 16);
341 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(30, 30)) == TRUE, "TB_SETBITMAPSIZE failed\n");
342 UpdateWindow(hToolbar);
343 CHECK_IMAGELIST(8, 30, 30);
344 /* when the width or height is zero, set it to 1 */
345 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(0, 0)) == TRUE, "TB_SETBITMAPSIZE failed\n");
346 UpdateWindow(hToolbar);
347 CHECK_IMAGELIST(208, 1, 1);
348 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(0, 5)) == TRUE, "TB_SETBITMAPSIZE failed\n");
349 UpdateWindow(hToolbar);
350 CHECK_IMAGELIST(208, 1, 5);
351 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(5, 0)) == TRUE, "TB_SETBITMAPSIZE failed\n");
352 UpdateWindow(hToolbar);
353 CHECK_IMAGELIST(41, 5, 1);
355 /* the control can add bitmaps to an existing image list */
356 rebuild_toolbar(&hToolbar);
357 himl = ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_80x15), 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
358 ok(himl != NULL, "failed to create imagelist\n");
359 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
360 CHECK_IMAGELIST(4, 20, 15);
361 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
362 CHECK_IMAGELIST(10, 20, 15);
363 /* however TB_SETBITMAPSIZE/add std bitmap won't change the image size (the button size does change) */
364 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
365 UpdateWindow(hToolbar);
366 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(15, 14), "%x");
367 CHECK_IMAGELIST(10, 20, 15);
368 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 1, "TB_SETBITMAPSIZE failed\n");
369 UpdateWindow(hToolbar);
370 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(23, 22), "%x");
371 CHECK_IMAGELIST(22, 20, 15);
373 /* check standard bitmaps */
374 addbmp.hInst = HINST_COMMCTRL;
375 addbmp.nID = IDB_STD_SMALL_COLOR;
376 rebuild_toolbar(&hToolbar);
377 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
378 CHECK_IMAGELIST(15, 16, 16);
379 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(23, 22), "%x");
380 addbmp.nID = IDB_STD_LARGE_COLOR;
381 rebuild_toolbar(&hToolbar);
382 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
383 CHECK_IMAGELIST(15, 24, 24);
384 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(31, 30), "%x");
386 addbmp.nID = IDB_VIEW_SMALL_COLOR;
387 rebuild_toolbar(&hToolbar);
388 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
389 CHECK_IMAGELIST(12, 16, 16);
390 addbmp.nID = IDB_VIEW_LARGE_COLOR;
391 rebuild_toolbar(&hToolbar);
392 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
393 CHECK_IMAGELIST(12, 24, 24);
395 addbmp.nID = IDB_HIST_SMALL_COLOR;
396 rebuild_toolbar(&hToolbar);
397 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
398 CHECK_IMAGELIST(5, 16, 16);
399 addbmp.nID = IDB_HIST_LARGE_COLOR;
400 rebuild_toolbar(&hToolbar);
401 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
402 CHECK_IMAGELIST(5, 24, 24);
405 DestroyWindow(hToolbar);
408 #define CHECK_STRING_TABLE(count, tab) { \
411 for (_i = 0; _i < (count); _i++) {\
412 ret = SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, _i), (LPARAM)_buf); \
413 ok(ret >= 0, "TB_GETSTRING - unexpected return %d while checking string %d\n", ret, _i); \
415 ok(strcmp(_buf, (tab)[_i]) == 0, "Invalid string #%d - '%s' vs '%s'\n", _i, (tab)[_i], _buf); \
417 ok(SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, (count)), (LPARAM)_buf) == -1, \
418 "Too many string in table\n"); \
421 static void test_add_string(void)
423 LPCSTR test1 = "a\0b\0";
424 LPCSTR test2 = "|a|b||\0";
425 LPCSTR ret1[] = {"a", "b"};
426 LPCSTR ret2[] = {"a", "b", "|a|b||"};
427 LPCSTR ret3[] = {"a", "b", "|a|b||", "p", "q"};
428 LPCSTR ret4[] = {"a", "b", "|a|b||", "p", "q", "p"};
429 LPCSTR ret5[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q"};
430 LPCSTR ret6[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q"};
431 LPCSTR ret7[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q", "br", "c", "d"};
432 HWND hToolbar = NULL;
436 rebuild_toolbar(&hToolbar);
437 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)test1);
438 ok(ret == 0, "TB_ADDSTRINGA - unexpected return %d\n", ret);
439 CHECK_STRING_TABLE(2, ret1);
440 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)test2);
441 ok(ret == 2, "TB_ADDSTRINGA - unexpected return %d\n", ret);
442 CHECK_STRING_TABLE(3, ret2);
444 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD1);
445 ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
446 CHECK_STRING_TABLE(3, ret2);
447 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD2);
448 ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
449 CHECK_STRING_TABLE(5, ret3);
450 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD3);
451 ok(ret == 5, "TB_ADDSTRINGA - unexpected return %d\n", ret);
452 CHECK_STRING_TABLE(6, ret4);
453 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD4);
454 ok(ret == 6, "TB_ADDSTRINGA - unexpected return %d\n", ret);
455 CHECK_STRING_TABLE(8, ret5);
456 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD5);
457 ok(ret == 8, "TB_ADDSTRINGA - unexpected return %d\n", ret);
458 CHECK_STRING_TABLE(11, ret6);
459 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD7);
460 ok(ret == 11, "TB_ADDSTRINGA - unexpected return %d\n", ret);
461 CHECK_STRING_TABLE(14, ret7);
463 ZeroMemory(&button, sizeof(button));
464 button.iString = (UINT_PTR)"Test";
465 SendMessageA(hToolbar, TB_INSERTBUTTONA, 0, (LPARAM)&button);
466 CHECK_STRING_TABLE(14, ret7);
467 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&button);
468 CHECK_STRING_TABLE(14, ret7);
470 DestroyWindow(hToolbar);
473 static void expect_hot_notify(int idold, int idnew)
475 g_fExpectedHotItemOld = idold;
476 g_fExpectedHotItemNew = idnew;
477 g_fReceivedHotItemChange = FALSE;
480 #define check_hot_notify() \
481 ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n"); \
482 g_fExpectedHotItemOld = g_fExpectedHotItemNew = 0;
484 static void test_hotitem(void)
486 HWND hToolbar = NULL;
490 g_fBlockHotItemChange = FALSE;
492 rebuild_toolbar_with_buttons(&hToolbar);
493 /* set TBSTYLE_FLAT. comctl5 allows hot items only for such toolbars.
494 * comctl6 doesn't have this requirement even when theme == NULL */
495 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_FLAT | GetWindowLong(hToolbar, GWL_STYLE));
496 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
497 ok(ret == -1, "Hot item: %ld, expected -1\n", ret);
498 ret = SendMessage(hToolbar, TB_SETHOTITEM, 1, 0);
499 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
500 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
501 ok(ret == 1, "Hot item: %ld, expected 1\n", ret);
502 ret = SendMessage(hToolbar, TB_SETHOTITEM, 2, 0);
503 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
505 ret = SendMessage(hToolbar, TB_SETHOTITEM, 0xbeef, 0);
506 ok(ret == 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
507 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
508 ok(ret == 2, "Hot item: %lx, expected 2\n", ret);
509 ret = SendMessage(hToolbar, TB_SETHOTITEM, -0xbeef, 0);
510 ok(ret == 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
511 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
512 ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
514 expect_hot_notify(0, 7);
515 ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
516 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
518 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
519 ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
520 g_fBlockHotItemChange = TRUE;
521 ret = SendMessage(hToolbar, TB_SETHOTITEM, 2, 0);
522 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
523 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
524 ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
525 g_fBlockHotItemChange = FALSE;
527 g_fReceivedHotItemChange = FALSE;
528 ret = SendMessage(hToolbar, TB_SETHOTITEM, 0xbeaf, 0);
529 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
530 ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received for invalid parameter\n");
532 g_fReceivedHotItemChange = FALSE;
533 ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
534 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
535 ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received after a duplication\n");
537 expect_hot_notify(7, 0);
538 ret = SendMessage(hToolbar, TB_SETHOTITEM, -0xbeaf, 0);
539 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
541 SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
543 /* setting disabled buttons will generate a notify with the button id but no button will be hot */
544 expect_hot_notify(7, 9);
545 ret = SendMessage(hToolbar, TB_SETHOTITEM, 4, 0);
546 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
548 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
549 ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
550 /* enabling the button won't change that */
551 SendMessage(hToolbar, TB_ENABLEBUTTON, 9, TRUE);
552 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
553 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
555 /* disabling a hot button works */
556 ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
557 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
558 g_fReceivedHotItemChange = FALSE;
559 SendMessage(hToolbar, TB_ENABLEBUTTON, 7, FALSE);
560 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
561 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
562 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
564 SendMessage(hToolbar, TB_SETHOTITEM, 1, 0);
565 tbinfo.cbSize = sizeof(TBBUTTONINFO);
566 tbinfo.dwMask = TBIF_STATE;
567 tbinfo.fsState = 0; /* disabled */
568 g_fReceivedHotItemChange = FALSE;
569 ok(SendMessage(hToolbar, TB_SETBUTTONINFO, 1, (LPARAM)&tbinfo) == TRUE, "TB_SETBUTTONINFO failed\n");
570 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
571 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
572 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
574 DestroyWindow(hToolbar);
577 #if 0 /* use this to generate more tests*/
579 static void dump_sizes(HWND hToolbar)
583 int count = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0);
586 GetClientRect(hToolbar, &r);
587 SendMessageA(hToolbar, TB_GETMAXSIZE, 0, &sz);
588 printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r.left, r.top, r.right, r.bottom,
589 sz.cx, sz.cy, count);
590 for (i=0; i<count; i++)
592 SendMessageA(hToolbar, TB_GETITEMRECT, i, &r);
593 printf("%s{%3d, %3d, %3d, %3d}, ", (i%3==0 ? "\n " : ""), r.left, r.top, r.right, r.bottom);
595 printf("\n }, }, \n");
598 #define check_sizes() dump_sizes(hToolbar);
599 #define check_sizes_todo(todomask) dump_sizes(hToolbar);
611 static tbsize_result_t tbsize_results[] =
613 { {0, 0, 672, 26}, {100, 22}, 5, {
614 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
615 { 54, 2, 77, 24}, { 77, 2, 100, 24},
617 { {0, 0, 672, 26}, {146, 22}, 7, {
618 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
619 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
622 { {0, 0, 672, 48}, {146, 22}, 7, {
623 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
624 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
627 { {0, 0, 672, 26}, {146, 22}, 7, {
628 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
629 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
632 { {0, 0, 672, 26}, {192, 22}, 9, {
633 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
634 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
635 {123, 2, 146, 24}, {146, 2, 169, 24}, {169, 2, 192, 24},
637 { {0, 0, 672, 92}, {882, 22}, 39, {
638 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 0, 2, 8, 29},
639 { 0, 29, 23, 51}, { 23, 29, 46, 51}, { 46, 29, 69, 51},
640 { 69, 29, 92, 51}, { 92, 29, 115, 51}, {115, 29, 138, 51},
641 {138, 29, 161, 51}, {161, 29, 184, 51}, {184, 29, 207, 51},
642 {207, 29, 230, 51}, {230, 29, 253, 51}, {253, 29, 276, 51},
643 {276, 29, 299, 51}, {299, 29, 322, 51}, {322, 29, 345, 51},
644 {345, 29, 368, 51}, {368, 29, 391, 51}, {391, 29, 414, 51},
645 {414, 29, 437, 51}, {437, 29, 460, 51}, {460, 29, 483, 51},
646 {483, 29, 506, 51}, {506, 29, 529, 51}, {529, 29, 552, 51},
647 {552, 29, 575, 51}, {575, 29, 598, 51}, {598, 29, 621, 51},
648 {621, 29, 644, 51}, {644, 29, 667, 51}, { 0, 51, 23, 73},
649 { 23, 51, 46, 73}, { 46, 51, 69, 73}, { 69, 51, 92, 73},
650 { 92, 51, 115, 73}, {115, 51, 138, 73}, {138, 51, 161, 73},
652 { {0, 0, 48, 226}, {23, 140}, 7, {
653 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 94, 24},
654 { 94, 2, 117, 24}, {117, 2, 140, 24}, {140, 2, 163, 24},
657 { {0, 0, 92, 226}, {23, 140}, 7, {
658 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 0, 24, 92, 32},
659 { 0, 32, 23, 54}, { 23, 32, 46, 54}, { 46, 32, 69, 54},
662 { {0, 0, 672, 26}, {194, 30}, 7, {
663 { 0, 2, 31, 32}, { 31, 2, 62, 32}, { 62, 2, 70, 32},
664 { 70, 2, 101, 32}, {101, 2, 132, 32}, {132, 2, 163, 32},
667 { {0, 0, 672, 64}, {194, 30}, 7, {
668 { 0, 2, 31, 32}, { 31, 2, 62, 32}, { 62, 2, 70, 32},
669 { 70, 2, 101, 32}, {101, 2, 132, 32}, {132, 2, 163, 32},
672 { {0, 0, 672, 64}, {194, 30}, 7, {
673 { 0, 0, 31, 30}, { 31, 0, 62, 30}, { 62, 0, 70, 30},
674 { 70, 0, 101, 30}, {101, 0, 132, 30}, {132, 0, 163, 30},
677 { {0, 0, 124, 226}, {31, 188}, 7, {
678 { 0, 0, 31, 30}, { 31, 0, 62, 30}, { 0, 30, 124, 38},
679 { 0, 38, 31, 68}, { 31, 38, 62, 68}, { 62, 38, 93, 68},
682 { {0, 0, 672, 26}, {146, 22}, 7, {
683 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
684 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
687 { {0, 0, 672, 26}, {146, 100}, 7, {
688 { 0, 0, 23, 100}, { 23, 0, 46, 100}, { 46, 0, 54, 100},
689 { 54, 0, 77, 100}, { 77, 0, 100, 100}, {100, 0, 123, 100},
692 { {0, 0, 672, 26}, {215, 100}, 10, {
693 { 0, 0, 23, 100}, { 23, 0, 46, 100}, { 46, 0, 54, 100},
694 { 54, 0, 77, 100}, { 77, 0, 100, 100}, {100, 0, 123, 100},
695 {123, 0, 146, 100}, {146, 0, 169, 100}, {169, 0, 192, 100},
698 { {0, 0, 672, 26}, {238, 39}, 11, {
699 { 0, 0, 23, 39}, { 23, 0, 46, 39}, { 46, 0, 54, 39},
700 { 54, 0, 77, 39}, { 77, 0, 100, 39}, {100, 0, 123, 39},
701 {123, 0, 146, 39}, {146, 0, 169, 39}, {169, 0, 192, 39},
702 {192, 0, 215, 39}, {215, 0, 238, 39},
704 { {0, 0, 672, 26}, {238, 22}, 11, {
705 { 0, 0, 23, 22}, { 23, 0, 46, 22}, { 46, 0, 54, 22},
706 { 54, 0, 77, 22}, { 77, 0, 100, 22}, {100, 0, 123, 22},
707 {123, 0, 146, 22}, {146, 0, 169, 22}, {169, 0, 192, 22},
708 {192, 0, 215, 22}, {215, 0, 238, 22},
710 { {0, 0, 672, 26}, {489, 39}, 3, {
711 { 0, 2, 163, 41}, {163, 2, 330, 41}, {330, 2, 493, 41},
713 { {0, 0, 672, 104}, {978, 24}, 6, {
714 { 0, 2, 163, 26}, {163, 2, 326, 26}, {326, 2, 489, 26},
715 {489, 2, 652, 26}, {652, 2, 819, 26}, {819, 2, 850, 26},
717 { {0, 0, 672, 28}, {978, 38}, 6, {
718 { 0, 0, 163, 38}, {163, 0, 326, 38}, {326, 0, 489, 38},
719 {489, 0, 652, 38}, {652, 0, 819, 38}, {819, 0, 850, 38},
721 { {0, 0, 672, 100}, {239, 102}, 3, {
722 { 0, 2, 100, 102}, {100, 2, 139, 102}, {139, 2, 239, 102},
724 { {0, 0, 672, 42}, {185, 40}, 3, {
725 { 0, 2, 75, 40}, {75, 2, 118, 40}, {118, 2, 185, 40},
727 { {0, 0, 672, 42}, {67, 40}, 1, {
730 { {0, 0, 672, 42}, {67, 41}, 2, {
731 { 0, 2, 672, 41}, { 0, 41, 672, 80},
735 static int tbsize_numtests = 0;
737 #define check_sizes_todo(todomask) { \
739 int buttonCount, i, mask=(todomask); \
740 tbsize_result_t *res = &tbsize_results[tbsize_numtests]; \
741 assert(tbsize_numtests < sizeof(tbsize_results)/sizeof(tbsize_results[0])); \
742 GetClientRect(hToolbar, &rc); \
743 /*check_rect("client", rc, res->rcClient);*/ \
744 buttonCount = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0); \
745 compare(buttonCount, res->nButtons, "%d"); \
746 for (i=0; i<min(buttonCount, res->nButtons); i++) { \
747 ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \
749 check_rect("button", rc, res->rcButtons[i]); \
751 todo_wine { check_rect("button", rc, res->rcButtons[i]); } \
758 #define check_sizes() check_sizes_todo(0)
762 static TBBUTTON buttons1[] = {
763 {0, 10, TBSTATE_WRAP|TBSTATE_ENABLED, 0, {0, }, 0, -1},
764 {0, 11, 0, 0, {0, }, 0, -1},
766 static TBBUTTON buttons2[] = {
767 {0, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
768 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
770 static TBBUTTON buttons3[] = {
771 {0, 30, TBSTATE_ENABLED, 0, {0, }, 0, 0},
772 {0, 31, TBSTATE_ENABLED, 0, {0, }, 0, 1},
773 {0, 32, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, 1},
774 {0, 33, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, (UINT_PTR)"Tst"}
777 static void test_sizes(void)
779 HWND hToolbar = NULL;
785 rebuild_toolbar_with_buttons(&hToolbar);
786 style = GetWindowLong(hToolbar, GWL_STYLE);
787 ok(style == (WS_CHILD|WS_VISIBLE|CCS_TOP), "Invalid style %x\n", style);
789 /* the TBSTATE_WRAP makes a second row */
790 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
792 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
794 /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */
795 SetWindowLong(hToolbar, GWL_STYLE, style|TBSTYLE_WRAPABLE);
797 /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */
798 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
800 /* only after adding enough buttons the bar will be wrapped on a
801 * separator and then on the first button */
803 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
804 check_sizes_todo(0x4);
806 rebuild_toolbar_with_buttons(&hToolbar);
807 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
808 /* setting the buttons vertical will only change the window client size */
809 SetWindowLong(hToolbar, GWL_STYLE, style | CCS_VERT);
810 SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
811 check_sizes_todo(0x3c);
812 /* with a TBSTYLE_WRAPABLE a wrapping will occur on the separator */
813 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_WRAPABLE | CCS_VERT);
814 SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
815 check_sizes_todo(0x7c);
817 rebuild_toolbar_with_buttons(&hToolbar);
818 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
819 /* a TB_SETBITMAPSIZE changes button sizes*/
820 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
823 /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */
824 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
825 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
827 /* but after a TB_SETBITMAPSIZE the top margins is changed */
828 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20));
829 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
831 /* some vertical toolbar sizes */
832 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT | TBSTYLE_WRAPABLE | CCS_VERT);
833 check_sizes_todo(0x7c);
835 rebuild_toolbar_with_buttons(&hToolbar);
836 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
837 /* newly added buttons will be use the previous margin */
838 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons2);
840 /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */
841 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
842 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n");
843 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
844 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
845 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 100), "Unexpected button size\n");
846 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n");
847 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
848 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
849 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 100), "Unexpected button size\n");
851 /* add some buttons with non-default sizes */
852 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons2);
853 SendMessageA(hToolbar, TB_INSERTBUTTON, -1, (LPARAM)&buttons2[0]);
855 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]);
856 /* TB_ADDSTRING resets the size */
857 SendMessageA(hToolbar, TB_ADDSTRING, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
858 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 39), "Unexpected button size\n");
860 /* TB_SETBUTTONSIZE can be used to crop the text */
861 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
862 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
864 /* the default size is bitmap size + padding */
865 SendMessageA(hToolbar, TB_SETPADDING, 0, MAKELONG(1, 1));
866 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
867 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(17, 17), "Unexpected button size\n");
868 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(3, 3));
869 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
870 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(4, 4), "Unexpected button size\n");
872 rebuild_toolbar(&hToolbar);
873 /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */
874 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
875 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(16, 15));
876 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 21), "Unexpected button size\n");
877 /* -1 in TB_SETBITMAPSIZE is a special code meaning that the coordinate shouldn't be changed */
878 add_128x15_bitmap(hToolbar, 16);
879 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(14, -1)), "TB_SETBITMAPSIZE failed\n");
880 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 21), "%x");
881 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, 12)), "TB_SETBITMAPSIZE failed\n");
882 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
883 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, -1)), "TB_SETBITMAPSIZE failed\n");
884 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
885 /* check the imagelist */
886 InvalidateRect(hToolbar, NULL, TRUE);
887 UpdateWindow(hToolbar);
888 CHECK_IMAGELIST(16, 14, 12);
890 rebuild_toolbar(&hToolbar);
891 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
892 /* the height is increased after a TB_ADDSTRING */
893 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 39), "Unexpected button size\n");
894 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
895 /* if a string is in the pool, even adding a button without a string resets the size */
896 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons2[0]);
897 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
898 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
899 /* an BTNS_AUTOSIZE button is also considered when computing the new size */
900 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[2]);
901 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 39), "Unexpected button size\n");
902 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]);
904 /* delete button doesn't change the buttons size */
905 SendMessageA(hToolbar, TB_DELETEBUTTON, 2, 0);
906 SendMessageA(hToolbar, TB_DELETEBUTTON, 1, 0);
907 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 39), "Unexpected button size\n");
908 /* TB_INSERTBUTTONS will */
909 SendMessageA(hToolbar, TB_INSERTBUTTON, 1, (LPARAM)&buttons2[0]);
910 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
912 /* TB_HIDEBUTTON and TB_MOVEBUTTON doesn't force a recalc */
913 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
914 ok(SendMessageA(hToolbar, TB_MOVEBUTTON, 0, 1), "TB_MOVEBUTTON failed\n");
915 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
916 ok(SendMessageA(hToolbar, TB_HIDEBUTTON, 20, TRUE), "TB_HIDEBUTTON failed\n");
917 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
918 /* however changing the hidden flag with TB_SETSTATE does */
919 ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED|TBSTATE_HIDDEN), "TB_SETSTATE failed\n");
920 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
921 ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED), "TB_SETSTATE failed\n");
922 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
924 /* TB_SETIMAGELIST always changes the height but the width only if necessary */
925 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
926 himl = ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_80x15), 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
927 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
928 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 21), "Unexpected button size\n");
929 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
930 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
931 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
932 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 21), "Unexpected button size\n");
933 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
934 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 7), "Unexpected button size\n");
935 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
936 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(8, 7), "Unexpected button size\n");
937 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
938 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 21), "Unexpected button size\n");
939 /* the text is taken into account */
940 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
941 SendMessageA(hToolbar, TB_ADDBUTTONS, 4, (LPARAM)buttons3);
942 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 38), "Unexpected button size\n");
943 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
944 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 24), "Unexpected button size\n");
945 /* the style change also comes into effect */
947 SetWindowLong(hToolbar, GWL_STYLE, GetWindowLong(hToolbar, GWL_STYLE) | TBSTYLE_FLAT);
948 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
949 check_sizes_todo(0x30); /* some small problems with BTNS_AUTOSIZE button sizes */
951 rebuild_toolbar(&hToolbar);
952 ImageList_Destroy(himl);
954 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]);
955 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 39), "Unexpected button size\n");
956 SendMessageA(hToolbar, TB_DELETEBUTTON, 0, 0);
957 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 39), "Unexpected button size\n");
959 rebuild_toolbar(&hToolbar);
961 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
962 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
963 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons2[0]) == 1, "TB_ADDBUTTONS failed\n");
964 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[2]) == 1, "TB_ADDBUTTONS failed\n");
965 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]) == 1, "TB_ADDBUTTONS failed\n");
966 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
969 rebuild_toolbar(&hToolbar);
970 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_LIST | GetWindowLong(hToolbar, GWL_STYLE));
971 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
972 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
973 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons2[0]) == 1, "TB_ADDBUTTONS failed\n");
974 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[2]) == 1, "TB_ADDBUTTONS failed\n");
975 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONS failed\n");
976 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
977 check_sizes_todo(0xff);
979 rebuild_toolbar(&hToolbar);
980 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_LIST | GetWindowLong(hToolbar, GWL_STYLE));
981 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
982 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
983 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONS failed\n");
984 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
987 rebuild_toolbar(&hToolbar);
988 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_WRAPABLE | GetWindowLong(hToolbar, GWL_STYLE));
989 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONS failed\n");
990 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONS failed\n");
992 tbinfo.cbSize = sizeof(TBBUTTONINFO);
993 tbinfo.dwMask = TBIF_SIZE | TBIF_BYINDEX;
994 ok(SendMessageA(hToolbar, TB_SETBUTTONINFO, 0, (LPARAM)&tbinfo) != 0, "TB_SETBUTTONINFO failed\n");
995 ok(SendMessageA(hToolbar, TB_SETBUTTONINFO, 1, (LPARAM)&tbinfo) != 0, "TB_SETBUTTONINFO failed\n");
996 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
999 DestroyWindow(hToolbar);
1002 static void test_getbuttoninfo(void)
1004 HWND hToolbar = NULL;
1007 rebuild_toolbar_with_buttons(&hToolbar);
1008 for (i = 0; i < 128; i++)
1014 tbi.dwMask = TBIF_BYINDEX | TBIF_COMMAND;
1015 ret = (int)SendMessage(hToolbar, TB_GETBUTTONINFO, 0, (LPARAM)&tbi);
1016 if (i == sizeof(TBBUTTONINFO)) {
1017 compare(ret, 0, "%d");
1019 compare(ret, -1, "%d");
1022 DestroyWindow(hToolbar);
1025 static void test_createtoolbarex(void)
1029 ZeroMemory(&btns, sizeof(btns));
1031 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1032 3, 20, 20, 16, 16, sizeof(TBBUTTON));
1033 CHECK_IMAGELIST(16, 20, 20);
1034 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x1a001b, "%x");
1035 DestroyWindow(hToolbar);
1037 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1038 3, 4, 4, 16, 16, sizeof(TBBUTTON));
1039 CHECK_IMAGELIST(32, 4, 4);
1040 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xa000b, "%x");
1041 DestroyWindow(hToolbar);
1043 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1044 3, 0, 8, 12, 12, sizeof(TBBUTTON));
1045 CHECK_IMAGELIST(16, 12, 12);
1046 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x120013, "%x");
1047 DestroyWindow(hToolbar);
1049 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1050 3, -1, 8, 12, 12, sizeof(TBBUTTON));
1051 CHECK_IMAGELIST(16, 12, 8);
1052 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0013, "%x");
1053 DestroyWindow(hToolbar);
1055 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1056 3, -1, 8, -1, 12, sizeof(TBBUTTON));
1057 CHECK_IMAGELIST(16, 16, 8);
1058 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0017, "%x");
1059 DestroyWindow(hToolbar);
1061 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1062 3, 0, 0, 12, -1, sizeof(TBBUTTON));
1063 CHECK_IMAGELIST(16, 12, 16);
1064 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x160013, "%x");
1065 DestroyWindow(hToolbar);
1067 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1068 3, 0, 0, 0, 12, sizeof(TBBUTTON));
1069 CHECK_IMAGELIST(16, 16, 16);
1070 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x160017, "%x");
1071 DestroyWindow(hToolbar);
1074 static void test_dispinfo(void)
1076 HWND hToolbar = NULL;
1077 const TBBUTTON buttons_disp[] = {
1078 {-1, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1079 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1083 rebuild_toolbar(&hToolbar);
1084 SendMessageA(hToolbar, TB_LOADIMAGES, IDB_HIST_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
1085 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons_disp);
1086 g_dwExpectedDispInfoMask = 1;
1087 /* Some TBN_GETDISPINFO tests will be done in MyWnd_Notify function.
1088 * We will receive TBN_GETDISPINFOW even if the control is ANSI */
1089 compare((BOOL)SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 0, "%d");
1090 ShowWindow(hToolbar, SW_SHOW);
1091 UpdateWindow(hToolbar);
1093 ret = (BOOL)SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, TRUE, 0);
1094 compare(ret, FALSE, "%d");
1095 compare(SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 1L, "%ld");
1096 InvalidateRect(hToolbar, NULL, FALSE);
1097 UpdateWindow(hToolbar);
1099 ret = (BOOL)SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, FALSE, 0);
1100 compare(ret, TRUE, "%d");
1101 compare(SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 0L, "%ld");
1102 InvalidateRect(hToolbar, NULL, FALSE);
1103 UpdateWindow(hToolbar);
1105 DestroyWindow(hToolbar);
1106 g_dwExpectedDispInfoMask = 0;
1116 static tbrows_result_t tbrows_results[] =
1118 {1, TRUE, 1}, /* 0: Simple case 9 in a row */
1119 {2, TRUE, 2}, /* 1: Another simple case 5 on one row, 4 on another*/
1120 {3, FALSE, 3}, /* 2: 3 lines - should be 3 lines of 3 buttons */
1121 {8, FALSE, 5}, /* 3: 8 lines - should be 5 lines of 2 buttons */
1122 {8, TRUE, 9}, /* 4: 8 lines but grow - should be 9 lines */
1123 {1, TRUE, 1} /* 5: Back to simple case */
1126 static void test_setrows(void)
1128 TBBUTTON buttons[9];
1133 MakeButton(buttons+i, 1000+i, TBSTYLE_FLAT | TBSTYLE_CHECKGROUP, 0);
1135 /* Test 1 - 9 buttons */
1136 hToolbar = CreateToolbarEx(hMainWnd,
1137 WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD | CCS_NORESIZE | CCS_NOPARENTALIGN
1138 | CCS_NOMOVEY | CCS_TOP,
1141 buttons, sizeof(buttons)/sizeof(buttons[0]),
1142 20, 20, 0, 0, sizeof(TBBUTTON));
1143 ok(hToolbar != NULL, "Toolbar creation\n");
1144 ok(SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
1146 /* test setting rows to each of 1-10 with bLarger true and false */
1147 for (i=0; i<(sizeof(tbrows_results) / sizeof(tbrows_result_t)); i++) {
1151 memset(&rc, 0xCC, sizeof(rc));
1152 SendMessageA(hToolbar, TB_SETROWS,
1153 MAKELONG(tbrows_results[i].nRows, tbrows_results[i].bLarger),
1156 rows = SendMessageA(hToolbar, TB_GETROWS, MAKELONG(0,0), MAKELONG(0,0));
1157 ok(rows == tbrows_results[i].expectedRows,
1158 "[%d] Unexpected number of rows %d (expected %d)\n", i, rows,
1159 tbrows_results[i].expectedRows);
1162 DestroyWindow(hToolbar);
1165 static void test_getstring(void)
1167 HWND hToolbar = NULL;
1170 static const char answer[] = "STR";
1171 static const WCHAR answerW[] = { 'S','T','R',0 };
1174 hToolbar = CreateWindowExA(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hMainWnd, (HMENU)5, GetModuleHandle(NULL), NULL);
1175 ok(hToolbar != NULL, "Toolbar creation problem\n");
1177 r = SendMessage(hToolbar, TB_GETSTRING, MAKEWPARAM(0, 0), 0);
1179 r = SendMessage(hToolbar, TB_GETSTRINGW, MAKEWPARAM(0, 0), 0);
1181 r = SendMessage(hToolbar, TB_ADDSTRING, 0, (LPARAM)answer);
1183 r = SendMessage(hToolbar, TB_GETSTRING, MAKEWPARAM(0, 0), 0);
1184 expect(lstrlenA(answer), r);
1185 r = SendMessage(hToolbar, TB_GETSTRINGW, MAKEWPARAM(0, 0), 0);
1186 expect(lstrlenA(answer), r);
1187 r = SendMessage(hToolbar, TB_GETSTRING, MAKEWPARAM(sizeof(str), 0), (LPARAM)str);
1188 expect(lstrlenA(answer), r);
1189 expect(0, lstrcmp(answer, str));
1190 r = SendMessage(hToolbar, TB_GETSTRINGW, MAKEWPARAM(sizeof(strW), 0), (LPARAM)strW);
1191 expect(lstrlenA(answer), r);
1192 expect(0, lstrcmpW(answerW, strW));
1194 DestroyWindow(hToolbar);
1203 InitCommonControls();
1205 wc.style = CS_HREDRAW | CS_VREDRAW;
1208 wc.hInstance = GetModuleHandleA(NULL);
1210 wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
1211 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1212 wc.lpszMenuName = NULL;
1213 wc.lpszClassName = "MyTestWnd";
1214 wc.lpfnWndProc = MyWndProc;
1215 RegisterClassA(&wc);
1217 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
1218 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
1219 GetClientRect(hMainWnd, &rc);
1220 ShowWindow(hMainWnd, SW_SHOW);
1227 test_getbuttoninfo();
1228 test_createtoolbarex();
1234 while(GetMessageA(&msg,0,0,0)) {
1235 TranslateMessage(&msg);
1236 DispatchMessageA(&msg);
1238 DestroyWindow(hMainWnd);