1 /* Unit test suite for list boxes.
3 * Copyright 2003 Ferenc Wagner
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/test.h"
33 #define WAIT Sleep (1000)
34 #define REDRAW RedrawWindow (handle, NULL, 0, RDW_UPDATENOW)
40 static const char * const strings[4] = {
44 "Fourth added which is very long because at some time we only had a 256 byte character buffer and that was overflowing in one of those applications that had a common dialog file open box and tried to add a 300 characters long custom filter string which of course the code did not like and crashed. Just make sure this string is longer than 256 characters."
47 static const char BAD_EXTENSION[] = "*.txtbad";
50 create_listbox (DWORD add_style, HWND parent)
56 handle=CreateWindow ("LISTBOX", "TestList",
57 (LBS_STANDARD & ~LBS_SORT) | add_style,
59 parent, (HMENU)ctl_id, NULL, 0);
62 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[0]);
63 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[1]);
64 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[2]);
65 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[3]);
68 ShowWindow (handle, SW_SHOW);
80 int selected, anchor, caret, selcount;
84 struct listbox_prop prop;
85 struct listbox_stat init, init_todo;
86 struct listbox_stat click, click_todo;
87 struct listbox_stat step, step_todo;
88 struct listbox_stat sel, sel_todo;
92 listbox_query (HWND handle, struct listbox_stat *results)
94 results->selected = SendMessage (handle, LB_GETCURSEL, 0, 0);
95 results->anchor = SendMessage (handle, LB_GETANCHORINDEX, 0, 0);
96 results->caret = SendMessage (handle, LB_GETCARETINDEX, 0, 0);
97 results->selcount = SendMessage (handle, LB_GETSELCOUNT, 0, 0);
101 buttonpress (HWND handle, WORD x, WORD y)
106 SendMessage (handle, WM_LBUTTONDOWN, (WPARAM) MK_LBUTTON, lp);
107 SendMessage (handle, WM_LBUTTONUP , (WPARAM) 0 , lp);
112 keypress (HWND handle, WPARAM keycode, BYTE scancode, BOOL extended)
114 LPARAM lp=1+(scancode<<16)+(extended?KEYEVENTF_EXTENDEDKEY:0);
117 SendMessage (handle, WM_KEYDOWN, keycode, lp);
118 SendMessage (handle, WM_KEYUP , keycode, lp | 0xc000000);
122 #define listbox_field_ok(t, s, f, got) \
123 ok (t.s.f==got.f, "style %#x, step " #s ", field " #f \
124 ": expected %d, got %d\n", (unsigned int)t.prop.add_style, \
127 #define listbox_todo_field_ok(t, s, f, got) \
128 if (t.s##_todo.f) todo_wine { listbox_field_ok(t, s, f, got); } \
129 else listbox_field_ok(t, s, f, got)
131 #define listbox_ok(t, s, got) \
132 listbox_todo_field_ok(t, s, selected, got); \
133 listbox_todo_field_ok(t, s, anchor, got); \
134 listbox_todo_field_ok(t, s, caret, got); \
135 listbox_todo_field_ok(t, s, selcount, got)
138 check (const struct listbox_test test)
140 struct listbox_stat answer;
141 HWND hLB=create_listbox (test.prop.add_style, 0);
146 listbox_query (hLB, &answer);
147 listbox_ok (test, init, answer);
149 SendMessage (hLB, LB_GETITEMRECT, (WPARAM) 1, (LPARAM) &second_item);
150 buttonpress(hLB, (WORD)second_item.left, (WORD)second_item.top);
152 listbox_query (hLB, &answer);
153 listbox_ok (test, click, answer);
155 keypress (hLB, VK_DOWN, 0x50, TRUE);
157 listbox_query (hLB, &answer);
158 listbox_ok (test, step, answer);
161 hLB=create_listbox (test.prop.add_style, 0);
163 SendMessage (hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, 2));
164 listbox_query (hLB, &answer);
165 listbox_ok (test, sel, answer);
168 DWORD size = SendMessage (hLB, LB_GETTEXTLEN, i, 0);
173 txt = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, size+1);
174 resA=SendMessageA(hLB, LB_GETTEXT, i, (LPARAM)txt);
175 ok(!strcmp (txt, strings[i]), "returned string for item %d does not match %s vs %s\n", i, txt, strings[i]);
177 txtw = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, 2*size+2);
178 resW=SendMessageW(hLB, LB_GETTEXT, i, (LPARAM)txtw);
180 trace("SendMessageW(LB_GETTEXT) not supported on this platform (resA=%d resW=%d), skipping...\n",
183 WideCharToMultiByte( CP_ACP, 0, txtw, -1, txt, size, NULL, NULL );
184 ok(!strcmp (txt, strings[i]), "returned string for item %d does not match %s vs %s\n", i, txt, strings[i]);
187 HeapFree (GetProcessHeap(), 0, txtw);
188 HeapFree (GetProcessHeap(), 0, txt);
191 /* Confirm the count of items, and that an invalid delete does not remove anything */
192 res = SendMessage (hLB, LB_GETCOUNT, 0, 0);
193 ok((res==4), "Expected 4 items, got %d\n", res);
194 res = SendMessage (hLB, LB_DELETESTRING, -1, 0);
195 ok((res==LB_ERR), "Expected LB_ERR items, got %d\n", res);
196 res = SendMessage (hLB, LB_DELETESTRING, 4, 0);
197 ok((res==LB_ERR), "Expected LB_ERR items, got %d\n", res);
198 res = SendMessage (hLB, LB_GETCOUNT, 0, 0);
199 ok((res==4), "Expected 4 items, got %d\n", res);
205 static void check_item_height(void)
213 hLB = create_listbox (0, 0);
214 ok ((hdc = GetDCEx( hLB, 0, DCX_CACHE )) != 0, "Can't get hdc\n");
215 ok ((font = GetCurrentObject(hdc, OBJ_FONT)) != 0, "Can't get the current font\n");
216 ok (GetTextMetrics( hdc, &tm ), "Can't read font metrics\n");
217 ReleaseDC( hLB, hdc);
219 ok (SendMessage(hLB, WM_SETFONT, (WPARAM)font, 0) == 0, "Can't set font\n");
221 itemHeight = SendMessage(hLB, LB_GETITEMHEIGHT, 0, 0);
222 ok (itemHeight == tm.tmHeight, "Item height wrong, got %d, expecting %d\n", itemHeight, tm.tmHeight);
226 hLB = CreateWindow ("LISTBOX", "TestList", LBS_OWNERDRAWVARIABLE,
227 0, 0, 100, 100, NULL, NULL, NULL, 0);
228 itemHeight = SendMessage(hLB, LB_GETITEMHEIGHT, 0, 0);
229 ok(itemHeight == tm.tmHeight, "itemHeight %d\n", itemHeight);
230 itemHeight = SendMessage(hLB, LB_GETITEMHEIGHT, 5, 0);
231 ok(itemHeight == tm.tmHeight, "itemHeight %d\n", itemHeight);
232 itemHeight = SendMessage(hLB, LB_GETITEMHEIGHT, -5, 0);
233 ok(itemHeight == tm.tmHeight, "itemHeight %d\n", itemHeight);
237 static LRESULT WINAPI main_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
243 RECT rc_item, rc_client, rc_clip;
244 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
246 trace("%p WM_DRAWITEM %08lx %08lx\n", hwnd, wparam, lparam);
248 ok(wparam == dis->CtlID, "got wParam=%08lx instead of %08x\n",
250 ok(dis->CtlType == ODT_LISTBOX, "wrong CtlType %04x\n", dis->CtlType);
252 GetClientRect(dis->hwndItem, &rc_client);
253 trace("hwndItem %p client rect (%d,%d-%d,%d)\n", dis->hwndItem,
254 rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
255 GetClipBox(dis->hDC, &rc_clip);
256 trace("clip rect (%d,%d-%d,%d)\n", rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom);
257 ok(EqualRect(&rc_client, &rc_clip), "client rect of the listbox should be equal to the clip box\n");
259 trace("rcItem (%d,%d-%d,%d)\n", dis->rcItem.left, dis->rcItem.top,
260 dis->rcItem.right, dis->rcItem.bottom);
261 SendMessage(dis->hwndItem, LB_GETITEMRECT, dis->itemID, (LPARAM)&rc_item);
262 trace("item rect (%d,%d-%d,%d)\n", rc_item.left, rc_item.top, rc_item.right, rc_item.bottom);
263 ok(EqualRect(&dis->rcItem, &rc_item), "item rects are not equal\n");
272 return DefWindowProc(hwnd, msg, wparam, lparam);
275 static void test_ownerdraw(void)
283 cls.lpfnWndProc = main_window_proc;
286 cls.hInstance = GetModuleHandle(0);
288 cls.hCursor = LoadCursor(0, (LPSTR)IDC_ARROW);
289 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
290 cls.lpszMenuName = NULL;
291 cls.lpszClassName = "main_window_class";
292 assert(RegisterClass(&cls));
294 parent = CreateWindowEx(0, "main_window_class", NULL,
295 WS_POPUP | WS_VISIBLE,
297 GetDesktopWindow(), 0,
298 GetModuleHandle(0), NULL);
301 hLB = create_listbox(LBS_OWNERDRAWFIXED | WS_CHILD | WS_VISIBLE, parent);
306 /* make height short enough */
307 SendMessage(hLB, LB_GETITEMRECT, 0, (LPARAM)&rc);
308 SetWindowPos(hLB, 0, 0, 0, 100, rc.bottom - rc.top + 1,
309 SWP_NOZORDER | SWP_NOMOVE);
311 /* make 0 item invisible */
312 SendMessage(hLB, LB_SETTOPINDEX, 1, 0);
313 ret = SendMessage(hLB, LB_GETTOPINDEX, 0, 0);
314 ok(ret == 1, "wrong top index %d\n", ret);
316 SendMessage(hLB, LB_GETITEMRECT, 0, (LPARAM)&rc);
317 trace("item 0 rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
318 ok(!IsRectEmpty(&rc), "empty item rect\n");
319 ok(rc.top < 0, "rc.top is not negative (%d)\n", rc.top);
322 DestroyWindow(parent);
325 #define listbox_test_query(exp, got) \
326 ok(exp.selected == got.selected, "expected selected %d, got %d\n", exp.selected, got.selected); \
327 ok(exp.anchor == got.anchor, "expected anchor %d, got %d\n", exp.anchor, got.anchor); \
328 ok(exp.caret == got.caret, "expected caret %d, got %d\n", exp.caret, got.caret); \
329 ok(exp.selcount == got.selcount, "expected selcount %d, got %d\n", exp.selcount, got.selcount);
331 static void test_selection(void)
333 static const struct listbox_stat test_nosel = { 0, LB_ERR, 0, 0 };
334 static const struct listbox_stat test_1 = { 0, LB_ERR, 0, 2 };
335 static const struct listbox_stat test_2 = { 0, LB_ERR, 0, 3 };
336 static const struct listbox_stat test_3 = { 0, LB_ERR, 0, 4 };
338 struct listbox_stat answer;
341 trace("testing LB_SELITEMRANGE\n");
343 hLB = create_listbox(LBS_EXTENDEDSEL, 0);
346 listbox_query(hLB, &answer);
347 listbox_test_query(test_nosel, answer);
349 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, 2));
350 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
351 listbox_query(hLB, &answer);
352 listbox_test_query(test_1, answer);
354 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
355 listbox_query(hLB, &answer);
356 listbox_test_query(test_nosel, answer);
358 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(0, 4));
359 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
360 listbox_query(hLB, &answer);
361 listbox_test_query(test_3, answer);
363 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
364 listbox_query(hLB, &answer);
365 listbox_test_query(test_nosel, answer);
367 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(-5, 5));
368 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
369 listbox_query(hLB, &answer);
370 listbox_test_query(test_nosel, answer);
372 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
373 listbox_query(hLB, &answer);
374 listbox_test_query(test_nosel, answer);
376 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(2, 10));
377 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
378 listbox_query(hLB, &answer);
379 listbox_test_query(test_1, answer);
381 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
382 listbox_query(hLB, &answer);
383 listbox_test_query(test_nosel, answer);
385 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(4, 10));
386 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
387 listbox_query(hLB, &answer);
388 listbox_test_query(test_nosel, answer);
390 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
391 listbox_query(hLB, &answer);
392 listbox_test_query(test_nosel, answer);
394 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(10, 1));
395 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
396 listbox_query(hLB, &answer);
397 listbox_test_query(test_2, answer);
399 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
400 listbox_query(hLB, &answer);
401 listbox_test_query(test_nosel, answer);
403 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, -1));
404 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
405 listbox_query(hLB, &answer);
406 listbox_test_query(test_2, answer);
411 static void test_listbox_height(void)
416 hList = CreateWindow( "ListBox", "list test", 0,
417 1, 1, 600, 100, NULL, NULL, NULL, NULL );
418 ok( hList != NULL, "failed to create listbox\n");
420 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi");
421 ok( id == 0, "item id wrong\n");
423 r = SendMessage( hList, LB_SETITEMHEIGHT, 0, MAKELPARAM( 20, 0 ));
424 ok( r == 0, "send message failed\n");
426 r = SendMessage(hList, LB_GETITEMHEIGHT, 0, 0 );
427 ok( r == 20, "height wrong\n");
429 r = SendMessage( hList, LB_SETITEMHEIGHT, 0, MAKELPARAM( 0, 30 ));
430 ok( r == -1, "send message failed\n");
432 r = SendMessage(hList, LB_GETITEMHEIGHT, 0, 0 );
433 ok( r == 20, "height wrong\n");
435 r = SendMessage( hList, LB_SETITEMHEIGHT, 0, MAKELPARAM( 0x100, 0 ));
436 ok( r == -1, "send message failed\n");
438 r = SendMessage(hList, LB_GETITEMHEIGHT, 0, 0 );
439 ok( r == 20, "height wrong\n");
441 r = SendMessage( hList, LB_SETITEMHEIGHT, 0, MAKELPARAM( 0xff, 0 ));
442 ok( r == 0, "send message failed\n");
444 r = SendMessage(hList, LB_GETITEMHEIGHT, 0, 0 );
445 ok( r == 0xff, "height wrong\n");
447 DestroyWindow( hList );
450 static void test_itemfrompoint(void)
452 /* WS_POPUP is required in order to have a more accurate size calculation (
453 without caption). LBS_NOINTEGRALHEIGHT is required in order to test
454 behavior of partially-displayed item.
456 HWND hList = CreateWindow( "ListBox", "list test",
457 WS_VISIBLE|WS_POPUP|LBS_NOINTEGRALHEIGHT,
458 1, 1, 600, 100, NULL, NULL, NULL, NULL );
462 /* For an empty listbox win2k returns 0x1ffff, win98 returns 0x10000 */
463 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( /* x */ 30, /* y */ 30 ));
464 ok( r == 0x1ffff || r == 0x10000, "ret %x\n", r );
466 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( 700, 30 ));
467 ok( r == 0x1ffff || r == 0x10000, "ret %x\n", r );
469 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( 30, 300 ));
470 ok( r == 0x1ffff || r == 0x10000, "ret %x\n", r );
472 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi");
473 ok( id == 0, "item id wrong\n");
474 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi1");
475 ok( id == 1, "item id wrong\n");
477 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( /* x */ 30, /* y */ 30 ));
478 ok( r == 0x1, "ret %x\n", r );
480 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( /* x */ 30, /* y */ 601 ));
481 ok( r == 0x10001, "ret %x\n", r );
483 /* Resize control so that below assertions about sizes are valid */
484 r = SendMessage( hList, LB_GETITEMRECT, 0, (LPARAM)&rc);
485 ok( r == 1, "ret %x\n", r);
486 r = MoveWindow(hList, 1, 1, 600, (rc.bottom - rc.top + 1) * 9 / 2, TRUE);
487 ok( r != 0, "ret %x\n", r);
489 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi2");
490 ok( id == 2, "item id wrong\n");
491 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi3");
492 ok( id == 3, "item id wrong\n");
493 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi4");
494 ok( id == 4, "item id wrong\n");
495 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi5");
496 ok( id == 5, "item id wrong\n");
497 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi6");
498 ok( id == 6, "item id wrong\n");
499 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi7");
500 ok( id == 7, "item id wrong\n");
502 /* Set the listbox up so that id 1 is at the top, this leaves 5
503 partially visible at the bottom and 6, 7 are invisible */
505 SendMessage( hList, LB_SETTOPINDEX, 1, 0);
506 r = SendMessage( hList, LB_GETTOPINDEX, 0, 0);
507 ok( r == 1, "top %d\n", r);
509 r = SendMessage( hList, LB_GETITEMRECT, 5, (LPARAM)&rc);
510 ok( r == 1, "ret %x\n", r);
511 r = SendMessage( hList, LB_GETITEMRECT, 6, (LPARAM)&rc);
512 ok( r == 0, "ret %x\n", r);
514 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(/* x */ 10, /* y */ 10) );
515 ok( r == 1, "ret %x\n", r);
517 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(1000, 10) );
518 ok( r == 0x10001, "ret %x\n", r );
520 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(10, -10) );
521 ok( r == 0x10001, "ret %x\n", r );
523 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(10, 100) );
524 ok( r == 0x10005, "item %x\n", r );
526 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(10, 200) );
527 ok( r == 0x10005, "item %x\n", r );
529 DestroyWindow( hList );
532 static void test_listbox_item_data(void)
537 hList = CreateWindow( "ListBox", "list test", 0,
538 1, 1, 600, 100, NULL, NULL, NULL, NULL );
539 ok( hList != NULL, "failed to create listbox\n");
541 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi");
542 ok( id == 0, "item id wrong\n");
544 r = SendMessage( hList, LB_SETITEMDATA, 0, MAKELPARAM( 20, 0 ));
545 ok(r == TRUE, "LB_SETITEMDATA returned %d instead of TRUE\n", r);
547 r = SendMessage( hList, LB_GETITEMDATA, 0, 0);
548 ok( r == 20, "get item data failed\n");
550 DestroyWindow( hList );
553 static void test_listbox_LB_DIR()
557 int itemCount_justFiles;
558 int itemCount_justDrives;
559 int itemCount_allFiles;
561 char pathBuffer[MAX_PATH];
566 file = CreateFileA( "wtest1.tmp.c", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL );
567 ok(file != INVALID_HANDLE_VALUE, "Error creating the test file: %d\n", GetLastError());
570 /* NOTE: for this test to succeed, there must be no subdirectories
571 under the current directory. In addition, there must be at least
572 one file that fits the wildcard w*.c . Normally, the test
573 directory itself satisfies both conditions.
575 hList = CreateWindow( "ListBox", "list test", WS_VISIBLE|WS_POPUP,
576 1, 1, 600, 100, NULL, NULL, NULL, NULL );
579 /* Test for standard usage */
581 /* This should list all the files in the test directory. */
582 strcpy(pathBuffer, "*");
583 SendMessage(hList, LB_RESETCONTENT, 0, 0);
584 res = SendMessage(hList, LB_DIR, 0, (LPARAM)pathBuffer);
585 ok (res >= 0, "SendMessage(LB_DIR, 0, *) failed - 0x%08x\n", GetLastError());
587 /* There should be some content in the listbox */
588 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
589 ok (itemCount > 0, "SendMessage(LB_DIR) did NOT fill the listbox!\n");
590 itemCount_allFiles = itemCount;
591 ok(res + 1 == itemCount,
592 "SendMessage(LB_DIR, 0, *) returned incorrect index (expected %d got %d)!\n",
595 /* This tests behavior when no files match the wildcard */
596 strcpy(pathBuffer, BAD_EXTENSION);
597 SendMessage(hList, LB_RESETCONTENT, 0, 0);
598 res = SendMessage(hList, LB_DIR, 0, (LPARAM)pathBuffer);
599 ok (res == -1, "SendMessage(LB_DIR, 0, %s) returned %d, expected -1\n", BAD_EXTENSION, res);
601 /* There should be NO content in the listbox */
602 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
603 ok (itemCount == 0, "SendMessage(LB_DIR) DID fill the listbox!\n");
606 /* This should list all the w*.c files in the test directory
607 * As of this writing, this includes win.c, winstation.c, wsprintf.c
609 strcpy(pathBuffer, "w*.c");
610 SendMessage(hList, LB_RESETCONTENT, 0, 0);
611 res = SendMessage(hList, LB_DIR, 0, (LPARAM)pathBuffer);
612 ok (res >= 0, "SendMessage(LB_DIR, 0, w*.c) failed - 0x%08x\n", GetLastError());
614 /* Path specification does NOT converted to uppercase */
615 ok (!strcmp(pathBuffer, "w*.c"),
616 "expected no change to pathBuffer, got %s\n", pathBuffer);
618 /* There should be some content in the listbox */
619 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
620 ok (itemCount > 0, "SendMessage(LB_DIR) did NOT fill the listbox!\n");
621 itemCount_justFiles = itemCount;
622 ok(res + 1 == itemCount,
623 "SendMessage(LB_DIR, 0, w*.c) returned incorrect index (expected %d got %d)!\n",
626 /* Every single item in the control should start with a w and end in .c */
627 for (i = 0; i < itemCount; i++) {
628 memset(pathBuffer, 0, MAX_PATH);
629 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
630 p = pathBuffer + strlen(pathBuffer);
631 ok(((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
632 (*(p-1) == 'c' || *(p-1) == 'C') &&
633 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
636 /* Test DDL_DIRECTORY */
637 strcpy(pathBuffer, "*");
638 SendMessage(hList, LB_RESETCONTENT, 0, 0);
639 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY, (LPARAM)pathBuffer);
640 ok (res > 0, "SendMessage(LB_DIR, DDL_DIRECTORY, *) failed - 0x%08x\n", GetLastError());
642 /* There should be some content in the listbox.
643 * All files plus "[..]"
645 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
646 ok (itemCount == itemCount_allFiles + 1,
647 "SendMessage(LB_DIR, DDL_DIRECTORY, *) filled with %d entries, expected %d\n",
648 itemCount, itemCount_allFiles + 1);
649 ok(res + 1 == itemCount,
650 "SendMessage(LB_DIR, DDL_DIRECTORY, *) returned incorrect index (expected %d got %d)!\n",
653 /* This tests behavior when no files match the wildcard */
654 strcpy(pathBuffer, BAD_EXTENSION);
655 SendMessage(hList, LB_RESETCONTENT, 0, 0);
656 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY, (LPARAM)pathBuffer);
657 ok (res == -1, "SendMessage(LB_DIR, DDL_DIRECTORY, %s) returned %d, expected -1\n", BAD_EXTENSION, res);
659 /* There should be NO content in the listbox */
660 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
661 ok (itemCount == 0, "SendMessage(LB_DIR) DID fill the listbox!\n");
664 /* Test DDL_DIRECTORY */
665 strcpy(pathBuffer, "w*.c");
666 SendMessage(hList, LB_RESETCONTENT, 0, 0);
667 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY, (LPARAM)pathBuffer);
668 ok (res >= 0, "SendMessage(LB_DIR, DDL_DIRECTORY, w*.c) failed - 0x%08x\n", GetLastError());
670 /* There should be some content in the listbox. Since the parent directory does not
671 * fit w*.c, there should be exactly the same number of items as without DDL_DIRECTORY
673 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
674 ok (itemCount == itemCount_justFiles,
675 "SendMessage(LB_DIR, DDL_DIRECTORY, w*.c) filled with %d entries, expected %d\n",
676 itemCount, itemCount_justFiles);
677 ok(res + 1 == itemCount,
678 "SendMessage(LB_DIR, DDL_DIRECTORY, w*.c) returned incorrect index (expected %d got %d)!\n",
681 /* Every single item in the control should start with a w and end in .c. */
682 for (i = 0; i < itemCount; i++) {
683 memset(pathBuffer, 0, MAX_PATH);
684 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
685 p = pathBuffer + strlen(pathBuffer);
687 ((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
688 (*(p-1) == 'c' || *(p-1) == 'C') &&
689 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
693 /* Test DDL_DRIVES|DDL_EXCLUSIVE */
694 strcpy(pathBuffer, "*");
695 SendMessage(hList, LB_RESETCONTENT, 0, 0);
696 res = SendMessage(hList, LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
697 ok (res > 0, "SendMessage(LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, *) failed - 0x%08x\n", GetLastError());
699 /* There should be some content in the listbox. In particular, there should
700 * be at least one element before, since the string "[-c-]" should
701 * have been added. Depending on the user setting, more drives might have
704 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
706 "SendMessage(LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, *) filled with %d entries, expected at least %d\n",
708 itemCount_justDrives = itemCount;
709 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, *) returned incorrect index!\n");
711 /* Every single item in the control should fit the format [-c-] */
712 for (i = 0; i < itemCount; i++) {
713 memset(pathBuffer, 0, MAX_PATH);
715 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
716 ok( strlen(pathBuffer) == 5, "Length of drive string is not 5\n" );
717 ok( sscanf(pathBuffer, "[-%c-]", &driveletter) == 1, "Element %d (%s) does not fit [-X-]\n", i, pathBuffer);
718 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
719 if (!(driveletter >= 'a' && driveletter <= 'z')) {
720 /* Correct after invalid entry is found */
721 trace("removing count of invalid entry %s\n", pathBuffer);
722 itemCount_justDrives--;
726 /* This tests behavior when no files match the wildcard */
727 strcpy(pathBuffer, BAD_EXTENSION);
728 SendMessage(hList, LB_RESETCONTENT, 0, 0);
729 res = SendMessage(hList, LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
730 ok (res == itemCount_justDrives -1, "SendMessage(LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, %s) returned %d, expected %d\n",
731 BAD_EXTENSION, res, itemCount_justDrives -1);
733 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
734 ok (itemCount == itemCount_justDrives, "SendMessage(LB_DIR) returned %d expected %d\n",
735 itemCount, itemCount_justDrives);
737 trace("Files with w*.c: %d Mapped drives: %d Directories: 1\n",
738 itemCount_justFiles, itemCount_justDrives);
740 /* Test DDL_DRIVES. */
741 strcpy(pathBuffer, "*");
742 SendMessage(hList, LB_RESETCONTENT, 0, 0);
743 res = SendMessage(hList, LB_DIR, DDL_DRIVES, (LPARAM)pathBuffer);
744 ok (res > 0, "SendMessage(LB_DIR, DDL_DRIVES, *) failed - 0x%08x\n", GetLastError());
746 /* There should be some content in the listbox. In particular, there should
747 * be at least one element before, since the string "[-c-]" should
748 * have been added. Depending on the user setting, more drives might have
751 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
752 ok (itemCount == itemCount_justDrives + itemCount_allFiles,
753 "SendMessage(LB_DIR, DDL_DRIVES, w*.c) filled with %d entries, expected %d\n",
754 itemCount, itemCount_justDrives + itemCount_allFiles);
755 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DRIVES, w*.c) returned incorrect index!\n");
757 /* This tests behavior when no files match the wildcard */
758 strcpy(pathBuffer, BAD_EXTENSION);
759 SendMessage(hList, LB_RESETCONTENT, 0, 0);
760 res = SendMessage(hList, LB_DIR, DDL_DRIVES, (LPARAM)pathBuffer);
761 ok (res == itemCount_justDrives -1, "SendMessage(LB_DIR, DDL_DRIVES, %s) returned %d, expected %d\n",
762 BAD_EXTENSION, res, itemCount_justDrives -1);
764 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
765 ok (itemCount == res + 1, "SendMessage(LB_DIR) returned %d expected %d\n", itemCount, res + 1);
768 /* Test DDL_DRIVES. */
769 strcpy(pathBuffer, "w*.c");
770 SendMessage(hList, LB_RESETCONTENT, 0, 0);
771 res = SendMessage(hList, LB_DIR, DDL_DRIVES, (LPARAM)pathBuffer);
772 ok (res > 0, "SendMessage(LB_DIR, DDL_DRIVES, w*.c) failed - 0x%08x\n", GetLastError());
774 /* There should be some content in the listbox. In particular, there should
775 * be at least one element before, since the string "[-c-]" should
776 * have been added. Depending on the user setting, more drives might have
779 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
780 ok (itemCount == itemCount_justDrives + itemCount_justFiles,
781 "SendMessage(LB_DIR, DDL_DRIVES, w*.c) filled with %d entries, expected %d\n",
782 itemCount, itemCount_justDrives + itemCount_justFiles);
783 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DRIVES, w*.c) returned incorrect index!\n");
785 /* Every single item in the control should fit the format [-c-], or w*.c */
786 for (i = 0; i < itemCount; i++) {
787 memset(pathBuffer, 0, MAX_PATH);
789 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
790 p = pathBuffer + strlen(pathBuffer);
791 if (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1) {
792 ok( strlen(pathBuffer) == 5, "Length of drive string is not 5\n" );
793 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
796 ((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
797 (*(p-1) == 'c' || *(p-1) == 'C') &&
798 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
803 /* Test DDL_DIRECTORY|DDL_DRIVES. This does *not* imply DDL_EXCLUSIVE */
804 strcpy(pathBuffer, "*");
805 SendMessage(hList, LB_RESETCONTENT, 0, 0);
806 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_DRIVES, (LPARAM)pathBuffer);
807 ok (res > 0, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, *) failed - 0x%08x\n", GetLastError());
809 /* There should be some content in the listbox. In particular, there should
810 * be exactly the number of plain files, plus the number of mapped drives.
812 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
813 ok (itemCount == itemCount_allFiles + itemCount_justDrives + 1,
814 "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES) filled with %d entries, expected %d\n",
815 itemCount, itemCount_allFiles + itemCount_justDrives + 1);
816 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, w*.c) returned incorrect index!\n");
818 /* Every single item in the control should start with a w and end in .c,
819 * except for the "[..]" string, which should appear exactly as it is,
820 * and the mapped drives in the format "[-X-]".
822 for (i = 0; i < itemCount; i++) {
823 memset(pathBuffer, 0, MAX_PATH);
825 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
826 p = pathBuffer + strlen(pathBuffer);
827 if (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1) {
828 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
832 /* This tests behavior when no files match the wildcard */
833 strcpy(pathBuffer, BAD_EXTENSION);
834 SendMessage(hList, LB_RESETCONTENT, 0, 0);
835 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_DRIVES, (LPARAM)pathBuffer);
836 ok (res == itemCount_justDrives -1, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, %s) returned %d, expected %d\n",
837 BAD_EXTENSION, res, itemCount_justDrives -1);
839 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
840 ok (itemCount == res + 1, "SendMessage(LB_DIR) returned %d expected %d\n", itemCount, res + 1);
844 /* Test DDL_DIRECTORY|DDL_DRIVES. */
845 strcpy(pathBuffer, "w*.c");
846 SendMessage(hList, LB_RESETCONTENT, 0, 0);
847 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_DRIVES, (LPARAM)pathBuffer);
848 ok (res > 0, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, w*.c) failed - 0x%08x\n", GetLastError());
850 /* There should be some content in the listbox. In particular, there should
851 * be exactly the number of plain files, plus the number of mapped drives.
853 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
854 ok (itemCount == itemCount_justFiles + itemCount_justDrives,
855 "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES) filled with %d entries, expected %d\n",
856 itemCount, itemCount_justFiles + itemCount_justDrives);
857 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, w*.c) returned incorrect index!\n");
859 /* Every single item in the control should start with a w and end in .c,
860 * except the mapped drives in the format "[-X-]". The "[..]" directory
863 for (i = 0; i < itemCount; i++) {
864 memset(pathBuffer, 0, MAX_PATH);
866 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
867 p = pathBuffer + strlen(pathBuffer);
868 if (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1) {
869 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
872 ((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
873 (*(p-1) == 'c' || *(p-1) == 'C') &&
874 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
878 /* Test DDL_DIRECTORY|DDL_EXCLUSIVE. */
879 strcpy(pathBuffer, "*");
880 SendMessage(hList, LB_RESETCONTENT, 0, 0);
881 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
882 ok (res == 0, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, *) failed - 0x%08x\n", GetLastError());
884 /* There should be exactly one element: "[..]" */
885 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
887 "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE) filled with %d entries, expected %d\n",
889 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, *) returned incorrect index!\n");
891 memset(pathBuffer, 0, MAX_PATH);
892 SendMessage(hList, LB_GETTEXT, 0, (LPARAM)pathBuffer);
893 ok( !strcmp(pathBuffer, "[..]"), "First (and only) element is not [..]\n");
895 /* This tests behavior when no files match the wildcard */
896 strcpy(pathBuffer, BAD_EXTENSION);
897 SendMessage(hList, LB_RESETCONTENT, 0, 0);
898 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
899 ok (res == -1, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, %s) returned %d, expected %d\n",
900 BAD_EXTENSION, res, -1);
902 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
903 ok (itemCount == res + 1, "SendMessage(LB_DIR) returned %d expected %d\n", itemCount, res + 1);
906 /* Test DDL_DIRECTORY|DDL_EXCLUSIVE. */
907 strcpy(pathBuffer, "w*.c");
908 SendMessage(hList, LB_RESETCONTENT, 0, 0);
909 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
910 ok (res == LB_ERR, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, w*.c) returned %d expected %d\n", res, LB_ERR);
912 /* There should be no elements, since "[..]" does not fit w*.c */
913 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
915 "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE) filled with %d entries, expected %d\n",
918 /* Test DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE. */
919 strcpy(pathBuffer, "*");
920 SendMessage(hList, LB_RESETCONTENT, 0, 0);
921 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
922 ok (res > 0, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, w*.c,) failed - 0x%08x\n", GetLastError());
924 /* There should be no plain files on the listbox */
925 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
926 ok (itemCount == itemCount_justDrives + 1,
927 "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE) filled with %d entries, expected %d\n",
928 itemCount, itemCount_justDrives + 1);
929 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, w*.c) returned incorrect index!\n");
931 for (i = 0; i < itemCount; i++) {
932 memset(pathBuffer, 0, MAX_PATH);
934 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
935 p = pathBuffer + strlen(pathBuffer);
936 if (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1) {
937 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
939 ok( !strcmp(pathBuffer, "[..]"), "Element %d (%s) does not fit expected [..]\n", i, pathBuffer);
943 /* This tests behavior when no files match the wildcard */
944 strcpy(pathBuffer, BAD_EXTENSION);
945 SendMessage(hList, LB_RESETCONTENT, 0, 0);
946 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
947 ok (res == itemCount_justDrives -1, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, %s) returned %d, expected %d\n",
948 BAD_EXTENSION, res, itemCount_justDrives -1);
950 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
951 ok (itemCount == res + 1, "SendMessage(LB_DIR) returned %d expected %d\n", itemCount, res + 1);
953 /* Test DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE. */
954 strcpy(pathBuffer, "w*.c");
955 SendMessage(hList, LB_RESETCONTENT, 0, 0);
956 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
957 ok (res > 0, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, w*.c,) failed - 0x%08x\n", GetLastError());
959 /* There should be no plain files on the listbox, and no [..], since it does not fit w*.c */
960 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
961 ok (itemCount == itemCount_justDrives,
962 "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE) filled with %d entries, expected %d\n",
963 itemCount, itemCount_justDrives);
964 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, w*.c) returned incorrect index!\n");
966 for (i = 0; i < itemCount; i++) {
967 memset(pathBuffer, 0, MAX_PATH);
969 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
970 p = pathBuffer + strlen(pathBuffer);
971 ok (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1, "Element %d (%s) does not fit [-X-]\n", i, pathBuffer);
972 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
974 DestroyWindow(hList);
976 DeleteFileA( "wtest1.tmp.c" );
982 #define ID_TEST_LABEL 1001
983 #define ID_TEST_LISTBOX 1002
985 static BOOL on_listbox_container_create (HWND hwnd, LPCREATESTRUCT lpcs)
987 g_label = CreateWindow(
989 "Contents of static control before DlgDirList.",
990 WS_CHILD | WS_VISIBLE,
992 hwnd, (HMENU)ID_TEST_LABEL, NULL, 0);
993 if (!g_label) return FALSE;
994 g_listBox = CreateWindow(
997 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_VSCROLL,
999 hwnd, (HMENU)ID_TEST_LISTBOX, NULL, 0);
1000 if (!g_listBox) return FALSE;
1005 static LRESULT CALLBACK listbox_container_window_procA (
1006 HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
1015 result = on_listbox_container_create(hwnd, (LPCREATESTRUCTA) lParam)
1019 result = DefWindowProcA (hwnd, uiMsg, wParam, lParam);
1025 static BOOL RegisterListboxWindowClass(HINSTANCE hInst)
1032 cls.hInstance = hInst;
1034 cls.hCursor = LoadCursorA (NULL, IDC_ARROW);
1035 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
1036 cls.lpszMenuName = NULL;
1037 cls.lpfnWndProc = listbox_container_window_procA;
1038 cls.lpszClassName = "ListboxContainerClass";
1039 if (!RegisterClassA (&cls)) return FALSE;
1044 static void test_listbox_dlgdir(void)
1049 int itemCount_justFiles;
1050 int itemCount_justDrives;
1052 char pathBuffer[MAX_PATH];
1053 char itemBuffer[MAX_PATH];
1054 char tempBuffer[MAX_PATH];
1059 file = CreateFileA( "wtest1.tmp.c", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL );
1060 ok(file != INVALID_HANDLE_VALUE, "Error creating the test file: %d\n", GetLastError());
1061 CloseHandle( file );
1063 /* NOTE: for this test to succeed, there must be no subdirectories
1064 under the current directory. In addition, there must be at least
1065 one file that fits the wildcard w*.c . Normally, the test
1066 directory itself satisfies both conditions.
1069 hInst = GetModuleHandleA(0);
1070 if (!RegisterListboxWindowClass(hInst)) assert(0);
1071 hWnd = CreateWindow("ListboxContainerClass", "ListboxContainerClass",
1072 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1073 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1074 NULL, NULL, hInst, 0);
1077 /* Test for standard usage */
1079 /* The following should be overwritten by the directory path */
1080 SendMessage(g_label, WM_SETTEXT, 0, (LPARAM)"default contents");
1082 /* This should list all the w*.c files in the test directory
1083 * As of this writing, this includes win.c, winstation.c, wsprintf.c
1085 strcpy(pathBuffer, "w*.c");
1086 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL, 0);
1087 ok (res == 1, "DlgDirList(*.c, 0) returned %d - expected 1 - 0x%08x\n", res, GetLastError());
1089 /* Path specification gets converted to uppercase */
1090 ok (!strcmp(pathBuffer, "W*.C"),
1091 "expected conversion to uppercase, got %s\n", pathBuffer);
1093 /* Loaded path should have overwritten the label text */
1094 SendMessage(g_label, WM_GETTEXT, (WPARAM)MAX_PATH, (LPARAM)pathBuffer);
1095 trace("Static control after DlgDirList: %s\n", pathBuffer);
1096 ok (strcmp("default contents", pathBuffer), "DlgDirList() did not modify static control!\n");
1098 /* There should be some content in the listbox */
1099 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1100 ok (itemCount > 0, "DlgDirList() did NOT fill the listbox!\n");
1101 itemCount_justFiles = itemCount;
1103 /* Every single item in the control should start with a w and end in .c */
1104 for (i = 0; i < itemCount; i++) {
1105 memset(pathBuffer, 0, MAX_PATH);
1106 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)pathBuffer);
1107 p = pathBuffer + strlen(pathBuffer);
1108 ok(((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
1109 (*(p-1) == 'c' || *(p-1) == 'C') &&
1110 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
1113 /* Test behavior when no files match the wildcard */
1114 strcpy(pathBuffer, BAD_EXTENSION);
1115 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL, 0);
1116 ok (res == 1, "DlgDirList(%s, 0) returned %d expected 1\n", BAD_EXTENSION, res);
1118 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1119 ok (itemCount == 0, "DlgDirList() DID fill the listbox!\n");
1121 /* Test DDL_DIRECTORY */
1122 strcpy(pathBuffer, "w*.c");
1123 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1125 ok (res == 1, "DlgDirList(*.c, DDL_DIRECTORY) failed - 0x%08x\n", GetLastError());
1127 /* There should be some content in the listbox. In particular, there should
1128 * be exactly one more element than before, since the string "[..]" should
1131 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1132 ok (itemCount == itemCount_justFiles + 1,
1133 "DlgDirList(DDL_DIRECTORY) filled with %d entries, expected %d\n",
1134 itemCount, itemCount_justFiles + 1);
1136 /* Every single item in the control should start with a w and end in .c,
1137 * except for the "[..]" string, which should appear exactly as it is.
1139 for (i = 0; i < itemCount; i++) {
1140 memset(pathBuffer, 0, MAX_PATH);
1141 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)pathBuffer);
1142 p = pathBuffer + strlen(pathBuffer);
1143 ok( !strcmp(pathBuffer, "[..]") ||
1144 ((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
1145 (*(p-1) == 'c' || *(p-1) == 'C') &&
1146 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
1149 /* Test behavior when no files match the wildcard */
1150 strcpy(pathBuffer, BAD_EXTENSION);
1151 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1153 ok (res == 1, "DlgDirList(%s, DDL_DIRECTORY) returned %d expected 1\n", BAD_EXTENSION, res);
1155 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1156 ok (itemCount == 1, "DlgDirList() incorrectly filled the listbox! (expected 1 got %d)\n",
1158 for (i = 0; i < itemCount; i++) {
1159 memset(pathBuffer, 0, MAX_PATH);
1160 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)pathBuffer);
1161 p = pathBuffer + strlen(pathBuffer);
1162 ok( !strcmp(pathBuffer, "[..]"), "Element %d (%s) does not fit requested [..]\n", i, pathBuffer);
1166 /* Test DDL_DRIVES. At least on WinXP-SP2, this implies DDL_EXCLUSIVE */
1167 strcpy(pathBuffer, "w*.c");
1168 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1170 ok (res == 1, "DlgDirList(*.c, DDL_DRIVES) failed - 0x%08x\n", GetLastError());
1172 /* There should be some content in the listbox. In particular, there should
1173 * be at least one element before, since the string "[-c-]" should
1174 * have been added. Depending on the user setting, more drives might have
1177 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1179 "DlgDirList(DDL_DRIVES) filled with %d entries, expected at least %d\n",
1181 itemCount_justDrives = itemCount;
1183 /* Every single item in the control should fit the format [-c-] */
1184 for (i = 0; i < itemCount; i++) {
1185 memset(pathBuffer, 0, MAX_PATH);
1187 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)pathBuffer);
1188 ok( strlen(pathBuffer) == 5, "Length of drive string is not 5\n" );
1189 ok( sscanf(pathBuffer, "[-%c-]", &driveletter) == 1, "Element %d (%s) does not fit [-X-]\n", i, pathBuffer);
1190 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
1191 if (!(driveletter >= 'a' && driveletter <= 'z')) {
1192 /* Correct after invalid entry is found */
1193 trace("removing count of invalid entry %s\n", pathBuffer);
1194 itemCount_justDrives--;
1198 /* Test behavior when no files match the wildcard */
1199 strcpy(pathBuffer, BAD_EXTENSION);
1200 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1202 ok (res == 1, "DlgDirList(%s, DDL_DRIVES) returned %d expected 1\n", BAD_EXTENSION, res);
1204 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1205 ok (itemCount == itemCount_justDrives, "DlgDirList() incorrectly filled the listbox!\n");
1208 /* Test DDL_DIRECTORY|DDL_DRIVES. This does *not* imply DDL_EXCLUSIVE */
1209 strcpy(pathBuffer, "w*.c");
1210 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1211 DDL_DIRECTORY|DDL_DRIVES);
1212 ok (res == 1, "DlgDirList(*.c, DDL_DIRECTORY|DDL_DRIVES) failed - 0x%08x\n", GetLastError());
1214 /* There should be some content in the listbox. In particular, there should
1215 * be exactly the number of plain files, plus the number of mapped drives,
1218 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1219 ok (itemCount == itemCount_justFiles + itemCount_justDrives + 1,
1220 "DlgDirList(DDL_DIRECTORY|DDL_DRIVES) filled with %d entries, expected %d\n",
1221 itemCount, itemCount_justFiles + itemCount_justDrives + 1);
1223 /* Every single item in the control should start with a w and end in .c,
1224 * except for the "[..]" string, which should appear exactly as it is,
1225 * and the mapped drives in the format "[-X-]".
1227 for (i = 0; i < itemCount; i++) {
1228 memset(pathBuffer, 0, MAX_PATH);
1230 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)pathBuffer);
1231 p = pathBuffer + strlen(pathBuffer);
1232 if (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1) {
1233 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
1235 ok( !strcmp(pathBuffer, "[..]") ||
1236 ((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
1237 (*(p-1) == 'c' || *(p-1) == 'C') &&
1238 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
1242 /* Test behavior when no files match the wildcard */
1243 strcpy(pathBuffer, BAD_EXTENSION);
1244 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1245 DDL_DIRECTORY|DDL_DRIVES);
1246 ok (res == 1, "DlgDirList(%s, DDL_DIRECTORY|DDL_DRIVES) returned %d expected 1\n", BAD_EXTENSION, res);
1248 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1249 ok (itemCount == itemCount_justDrives + 1,
1250 "DlgDirList() incorrectly filled the listbox! (expected %d got %d)\n",
1251 itemCount_justDrives + 1, itemCount);
1255 /* Test DDL_DIRECTORY|DDL_EXCLUSIVE. */
1256 strcpy(pathBuffer, "w*.c");
1257 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1258 DDL_DIRECTORY|DDL_EXCLUSIVE);
1259 ok (res == 1, "DlgDirList(*.c, DDL_DIRECTORY|DDL_EXCLUSIVE) failed - 0x%08x\n", GetLastError());
1261 /* There should be exactly one element: "[..]" */
1262 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1264 "DlgDirList(DDL_DIRECTORY|DDL_EXCLUSIVE) filled with %d entries, expected %d\n",
1267 memset(pathBuffer, 0, MAX_PATH);
1268 SendMessage(g_listBox, LB_GETTEXT, 0, (LPARAM)pathBuffer);
1269 ok( !strcmp(pathBuffer, "[..]"), "First (and only) element is not [..]\n");
1272 /* Test behavior when no files match the wildcard */
1273 strcpy(pathBuffer, BAD_EXTENSION);
1274 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1275 DDL_DIRECTORY|DDL_EXCLUSIVE);
1276 ok (res == 1, "DlgDirList(%s, DDL_DIRECTORY|DDL_EXCLUSIVE) returned %d expected 1\n", BAD_EXTENSION, res);
1278 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1279 ok (itemCount == 1, "DlgDirList() incorrectly filled the listbox!\n");
1282 /* Test DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE. */
1283 strcpy(pathBuffer, "w*.c");
1284 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1285 DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE);
1286 ok (res == 1, "DlgDirList(*.c, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE) failed - 0x%08x\n", GetLastError());
1288 /* There should be no plain files on the listbox */
1289 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1290 ok (itemCount == itemCount_justDrives + 1,
1291 "DlgDirList(DDL_DIRECTORY|DDL_EXCLUSIVE) filled with %d entries, expected %d\n",
1292 itemCount, itemCount_justDrives + 1);
1294 for (i = 0; i < itemCount; i++) {
1295 memset(pathBuffer, 0, MAX_PATH);
1297 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)pathBuffer);
1298 p = pathBuffer + strlen(pathBuffer);
1299 if (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1) {
1300 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
1302 ok( !strcmp(pathBuffer, "[..]"), "Element %d (%s) does not fit expected [..]\n", i, pathBuffer);
1306 /* Test behavior when no files match the wildcard */
1307 strcpy(pathBuffer, BAD_EXTENSION);
1308 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1309 DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE);
1310 ok (res == 1, "DlgDirList(%s, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE) returned %d expected 1\n", BAD_EXTENSION, res);
1312 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1313 ok (itemCount == itemCount_justDrives + 1, "DlgDirList() incorrectly filled the listbox!\n");
1316 /* Now test DlgDirSelectEx() in normal operation */
1317 /* Fill with everything - drives, directory and all plain files. */
1318 strcpy(pathBuffer, "*");
1319 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1320 DDL_DIRECTORY|DDL_DRIVES);
1321 ok (res != 0, "DlgDirList(*, DDL_DIRECTORY|DDL_DRIVES) failed - 0x%08x\n", GetLastError());
1323 SendMessage(g_listBox, LB_SETCURSEL, -1, 0); /* Unselect any current selection */
1324 memset(pathBuffer, 0, MAX_PATH);
1325 SetLastError(0xdeadbeef);
1326 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1327 ok (GetLastError() == 0xdeadbeef,
1328 "DlgDirSelectEx() with no selection modified last error code from 0xdeadbeef to 0x%08x\n",
1330 ok (res == 0, "DlgDirSelectEx() with no selection returned %d, expected 0\n", res);
1331 /* WinXP-SP2 leaves pathBuffer untouched, but Win98 fills it with garbage. */
1333 ok (strlen(pathBuffer) == 0, "DlgDirSelectEx() with no selection filled buffer with %s\n", pathBuffer);
1335 /* Test proper drive/dir/file recognition */
1336 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1337 for (i = 0; i < itemCount; i++) {
1338 memset(itemBuffer, 0, MAX_PATH);
1339 memset(pathBuffer, 0, MAX_PATH);
1340 memset(tempBuffer, 0, MAX_PATH);
1342 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)itemBuffer);
1343 res = SendMessage(g_listBox, LB_SETCURSEL, i, 0);
1344 ok (res == i, "SendMessage(LB_SETCURSEL, %d) failed\n", i);
1345 if (sscanf(itemBuffer, "[-%c-]", &driveletter) == 1) {
1346 /* Current item is a drive letter */
1347 SetLastError(0xdeadbeef);
1348 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1349 ok (GetLastError() == 0xdeadbeef,
1350 "DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x\n",
1352 ok(res == 1, "DlgDirSelectEx() thinks %s (%s) is not a drive/directory!\n", itemBuffer, pathBuffer);
1354 /* For drive letters, DlgDirSelectEx tacks on a colon */
1355 ok (pathBuffer[0] == driveletter && pathBuffer[1] == ':' && pathBuffer[2] == '\0',
1356 "%d: got \"%s\" expected \"%c:\"\n", i, pathBuffer, driveletter);
1357 } else if (itemBuffer[0] == '[') {
1358 /* Current item is the parent directory */
1359 SetLastError(0xdeadbeef);
1360 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1361 ok (GetLastError() == 0xdeadbeef,
1362 "DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x\n",
1364 ok(res == 1, "DlgDirSelectEx() thinks %s (%s) is not a drive/directory!\n", itemBuffer, pathBuffer);
1366 /* For directories, DlgDirSelectEx tacks on a backslash */
1367 p = pathBuffer + strlen(pathBuffer);
1368 ok (*(p-1) == '\\', "DlgDirSelectEx did NOT tack on a backslash to dir, got %s\n", pathBuffer);
1370 tempBuffer[0] = '[';
1371 strncpy(tempBuffer + 1, pathBuffer, strlen(pathBuffer) - 1);
1372 strcat(tempBuffer, "]");
1373 ok (!strcmp(tempBuffer, itemBuffer), "Formatted directory should be %s, got %s\n", tempBuffer, itemBuffer);
1375 /* Current item is a plain file */
1376 SetLastError(0xdeadbeef);
1377 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1378 ok (GetLastError() == 0xdeadbeef,
1379 "DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x\n",
1381 ok(res == 0, "DlgDirSelectEx() thinks %s (%s) is a drive/directory!\n", itemBuffer, pathBuffer);
1383 /* NOTE: WinXP tacks a period on all files that lack an extension. This affects
1384 * for example, "Makefile", which gets reported as "Makefile."
1386 strcpy(tempBuffer, itemBuffer);
1387 if (strchr(tempBuffer, '.') == NULL) strcat(tempBuffer, ".");
1388 ok (!strcmp(pathBuffer, tempBuffer), "Formatted file should be %s, got %s\n", tempBuffer, pathBuffer);
1392 /* Now test DlgDirSelectEx() in abnormal operation */
1393 /* Fill list with bogus entries, that look somewhat valid */
1394 SendMessage(g_listBox, LB_RESETCONTENT, 0, 0);
1395 SendMessage(g_listBox, LB_ADDSTRING, 0, (LPARAM)"[notexist.dir]");
1396 SendMessage(g_listBox, LB_ADDSTRING, 0, (LPARAM)"notexist.fil");
1397 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1398 for (i = 0; i < itemCount; i++) {
1399 memset(itemBuffer, 0, MAX_PATH);
1400 memset(pathBuffer, 0, MAX_PATH);
1401 memset(tempBuffer, 0, MAX_PATH);
1403 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)itemBuffer);
1404 res = SendMessage(g_listBox, LB_SETCURSEL, i, 0);
1405 ok (res == i, "SendMessage(LB_SETCURSEL, %d) failed\n", i);
1406 if (sscanf(itemBuffer, "[-%c-]", &driveletter) == 1) {
1407 /* Current item is a drive letter */
1408 SetLastError(0xdeadbeef);
1409 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1410 ok (GetLastError() == 0xdeadbeef,
1411 "DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x\n",
1413 ok(res == 1, "DlgDirSelectEx() thinks %s (%s) is not a drive/directory!\n", itemBuffer, pathBuffer);
1415 /* For drive letters, DlgDirSelectEx tacks on a colon */
1416 ok (pathBuffer[0] == driveletter && pathBuffer[1] == ':' && pathBuffer[2] == '\0',
1417 "%d: got \"%s\" expected \"%c:\"\n", i, pathBuffer, driveletter);
1418 } else if (itemBuffer[0] == '[') {
1419 /* Current item is the parent directory */
1420 SetLastError(0xdeadbeef);
1421 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1422 ok (GetLastError() == 0xdeadbeef,
1423 "DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x\n",
1425 ok(res == 1, "DlgDirSelectEx() thinks %s (%s) is not a drive/directory!\n", itemBuffer, pathBuffer);
1427 /* For directories, DlgDirSelectEx tacks on a backslash */
1428 p = pathBuffer + strlen(pathBuffer);
1429 ok (*(p-1) == '\\', "DlgDirSelectEx did NOT tack on a backslash to dir, got %s\n", pathBuffer);
1431 tempBuffer[0] = '[';
1432 strncpy(tempBuffer + 1, pathBuffer, strlen(pathBuffer) - 1);
1433 strcat(tempBuffer, "]");
1434 ok (!strcmp(tempBuffer, itemBuffer), "Formatted directory should be %s, got %s\n", tempBuffer, itemBuffer);
1436 /* Current item is a plain file */
1437 SetLastError(0xdeadbeef);
1438 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1439 ok (GetLastError() == 0xdeadbeef,
1440 "DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x\n",
1442 ok(res == 0, "DlgDirSelectEx() thinks %s (%s) is a drive/directory!\n", itemBuffer, pathBuffer);
1444 /* NOTE: WinXP and Win98 tack a period on all files that lack an extension.
1445 * This affects for example, "Makefile", which gets reported as "Makefile."
1447 strcpy(tempBuffer, itemBuffer);
1448 if (strchr(tempBuffer, '.') == NULL) strcat(tempBuffer, ".");
1449 ok (!strcmp(pathBuffer, tempBuffer), "Formatted file should be %s, got %s\n", tempBuffer, pathBuffer);
1452 DestroyWindow(hWnd);
1454 DeleteFileA( "wtest1.tmp.c" );
1459 const struct listbox_test SS =
1462 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
1463 { 1, 1, 1, LB_ERR}, {0,0,0,0},
1464 { 2, 2, 2, LB_ERR}, {0,0,0,0},
1465 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
1466 /* {selected, anchor, caret, selcount}{TODO fields} */
1467 const struct listbox_test SS_NS =
1469 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
1470 { 1, 1, 1, LB_ERR}, {0,0,0,0},
1471 { 2, 2, 2, LB_ERR}, {0,0,0,0},
1472 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
1473 const struct listbox_test MS =
1475 { 0, LB_ERR, 0, 0}, {0,0,0,0},
1476 { 1, 1, 1, 1}, {0,0,0,0},
1477 { 2, 1, 2, 1}, {0,0,0,0},
1478 { 0, LB_ERR, 0, 2}, {0,0,0,0}};
1479 const struct listbox_test MS_NS =
1480 {{LBS_MULTIPLESEL | LBS_NOSEL},
1481 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
1482 { 1, 1, 1, LB_ERR}, {0,0,0,0},
1483 { 2, 2, 2, LB_ERR}, {0,0,0,0},
1484 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
1485 const struct listbox_test ES =
1487 { 0, LB_ERR, 0, 0}, {0,0,0,0},
1488 { 1, 1, 1, 1}, {0,0,0,0},
1489 { 2, 2, 2, 1}, {0,0,0,0},
1490 { 0, LB_ERR, 0, 2}, {0,0,0,0}};
1491 const struct listbox_test ES_NS =
1492 {{LBS_EXTENDEDSEL | LBS_NOSEL},
1493 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
1494 { 1, 1, 1, LB_ERR}, {0,0,0,0},
1495 { 2, 2, 2, LB_ERR}, {0,0,0,0},
1496 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
1497 const struct listbox_test EMS =
1498 {{LBS_EXTENDEDSEL | LBS_MULTIPLESEL},
1499 { 0, LB_ERR, 0, 0}, {0,0,0,0},
1500 { 1, 1, 1, 1}, {0,0,0,0},
1501 { 2, 2, 2, 1}, {0,0,0,0},
1502 { 0, LB_ERR, 0, 2}, {0,0,0,0}};
1503 const struct listbox_test EMS_NS =
1504 {{LBS_EXTENDEDSEL | LBS_MULTIPLESEL | LBS_NOSEL},
1505 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
1506 { 1, 1, 1, LB_ERR}, {0,0,0,0},
1507 { 2, 2, 2, LB_ERR}, {0,0,0,0},
1508 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
1510 trace (" Testing single selection...\n");
1512 trace (" ... with NOSEL\n");
1514 trace (" Testing multiple selection...\n");
1516 trace (" ... with NOSEL\n");
1518 trace (" Testing extended selection...\n");
1520 trace (" ... with NOSEL\n");
1522 trace (" Testing extended and multiple selection...\n");
1524 trace (" ... with NOSEL\n");
1527 check_item_height();
1530 test_listbox_height();
1531 test_itemfrompoint();
1532 test_listbox_item_data();
1533 test_listbox_LB_DIR();
1534 test_listbox_dlgdir();