dpvoice: Add IDirectPlayVoiceClient Support.
[wine.git] / dlls / comdlg32 / tests / filedlg.c
blobe3d9bc7aa44e3c7a899d830354fac51b1cce9da8
1 /*
2 * Unit test suite for comdlg32 API functions: file dialogs
4 * Copyright 2007 Google (Lei Zhang)
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
22 #include <windows.h>
23 #include <wine/test.h>
25 #include "shlguid.h"
26 #define COBJMACROS
27 #include "shobjidl.h"
28 #include "commdlg.h"
29 #include "cderr.h"
30 #include "dlgs.h"
32 /* ##### */
34 static BOOL resizesupported = TRUE;
36 static void toolbarcheck( HWND hDlg)
38 /* test toolbar properties */
39 /* bug #10532 */
40 int maxtextrows;
41 HWND ctrl;
42 DWORD ret;
43 char classname[20];
45 for( ctrl = GetWindow( hDlg, GW_CHILD);
46 ctrl ; ctrl = GetWindow( ctrl, GW_HWNDNEXT)) {
47 GetClassNameA( ctrl, classname, 10);
48 classname[7] = '\0';
49 if( !strcmp( classname, "Toolbar")) break;
51 ok( ctrl != NULL, "could not get the toolbar control\n");
52 ret = SendMessageA( ctrl, TB_ADDSTRINGA, 0, (LPARAM)"winetestwinetest\0\0");
53 ok( ret == 0, "addstring returned %d (expected 0)\n", ret);
54 maxtextrows = SendMessageA( ctrl, TB_GETTEXTROWS, 0, 0);
55 ok( maxtextrows == 0 || broken(maxtextrows == 1), /* Win2k and below */
56 "Get(Max)TextRows returned %d (expected 0)\n", maxtextrows);
60 static UINT_PTR CALLBACK OFNHookProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
62 LPNMHDR nmh;
64 if( msg == WM_NOTIFY)
66 nmh = (LPNMHDR) lParam;
67 if( nmh->code == CDN_INITDONE)
69 PostMessageA( GetParent(hDlg), WM_COMMAND, IDCANCEL, FALSE);
70 } else if (nmh->code == CDN_FOLDERCHANGE )
72 char buf[1024];
73 int ret;
75 memset(buf, 0x66, sizeof(buf));
76 ret = SendMessageA( GetParent(hDlg), CDM_GETFOLDERIDLIST, 5, (LPARAM)buf);
77 ok(ret > 0, "CMD_GETFOLDERIDLIST not implemented\n");
78 if (ret > 5)
79 ok(buf[0] == 0x66 && buf[1] == 0x66, "CMD_GETFOLDERIDLIST: The buffer was touched on failure\n");
80 toolbarcheck( GetParent(hDlg));
84 return 0;
87 /* bug 6829 */
88 static void test_DialogCancel(void)
90 OPENFILENAMEA ofn;
91 BOOL result;
92 char szFileName[MAX_PATH] = "";
93 char szInitialDir[MAX_PATH];
95 GetWindowsDirectoryA(szInitialDir, MAX_PATH);
97 ZeroMemory(&ofn, sizeof(ofn));
99 ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
100 ofn.hwndOwner = NULL;
101 ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
102 ofn.lpstrFile = szFileName;
103 ofn.nMaxFile = MAX_PATH;
104 ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLEHOOK;
105 ofn.lpstrDefExt = "txt";
106 ofn.lpfnHook = OFNHookProc;
107 ofn.lpstrInitialDir = szInitialDir;
109 PrintDlgA(NULL);
110 ok(CDERR_INITIALIZATION == CommDlgExtendedError(),
111 "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
113 result = GetOpenFileNameA(&ofn);
114 ok(FALSE == result, "expected FALSE, got %d\n", result);
115 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
116 CommDlgExtendedError());
118 PrintDlgA(NULL);
119 ok(CDERR_INITIALIZATION == CommDlgExtendedError(),
120 "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
122 result = GetSaveFileNameA(&ofn);
123 ok(FALSE == result, "expected FALSE, got %d\n", result);
124 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
125 CommDlgExtendedError());
127 PrintDlgA(NULL);
128 ok(CDERR_INITIALIZATION == CommDlgExtendedError(),
129 "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
131 /* Before passing the ofn to Unicode functions, remove the ANSI strings */
132 ofn.lpstrFilter = NULL;
133 ofn.lpstrInitialDir = NULL;
134 ofn.lpstrDefExt = NULL;
136 PrintDlgA(NULL);
137 ok(CDERR_INITIALIZATION == CommDlgExtendedError(),
138 "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
140 SetLastError(0xdeadbeef);
141 result = GetOpenFileNameW((LPOPENFILENAMEW) &ofn);
142 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
143 win_skip("GetOpenFileNameW is not implemented\n");
144 else
146 ok(FALSE == result, "expected FALSE, got %d\n", result);
147 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n", CommDlgExtendedError());
150 SetLastError(0xdeadbeef);
151 result = GetSaveFileNameW((LPOPENFILENAMEW) &ofn);
152 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
153 win_skip("GetSaveFileNameW is not implemented\n");
154 else
156 ok(FALSE == result, "expected FALSE, got %d\n", result);
157 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n", CommDlgExtendedError());
161 static UINT_PTR CALLBACK create_view_window2_hook(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
163 if (msg == WM_NOTIFY)
165 if (((LPNMHDR)lParam)->code == CDN_FOLDERCHANGE)
167 IShellBrowser *shell_browser = (IShellBrowser *)SendMessageA(GetParent(dlg), WM_USER + 7 /* WM_GETISHELLBROWSER */, 0, 0);
168 IShellView *shell_view = NULL;
169 IShellView2 *shell_view2 = NULL;
170 SV2CVW2_PARAMS view_params;
171 FOLDERSETTINGS folder_settings;
172 HRESULT hr;
173 RECT rect = {0, 0, 0, 0};
175 hr = IShellBrowser_QueryActiveShellView(shell_browser, &shell_view);
176 ok(SUCCEEDED(hr), "QueryActiveShellView returned %#x\n", hr);
177 if (FAILED(hr)) goto cleanup;
179 hr = IShellView_QueryInterface(shell_view, &IID_IShellView2, (void **)&shell_view2);
180 if (hr == E_NOINTERFACE)
182 win_skip("IShellView2 not supported\n");
183 goto cleanup;
185 ok(SUCCEEDED(hr), "QueryInterface returned %#x\n", hr);
186 if (FAILED(hr)) goto cleanup;
188 hr = IShellView2_DestroyViewWindow(shell_view2);
189 ok(SUCCEEDED(hr), "DestroyViewWindow returned %#x\n", hr);
191 folder_settings.ViewMode = FVM_LIST;
192 folder_settings.fFlags = 0;
194 view_params.cbSize = sizeof(view_params);
195 view_params.psvPrev = NULL;
196 view_params.pfs = &folder_settings;
197 view_params.psbOwner = shell_browser;
198 view_params.prcView = &rect;
199 view_params.pvid = NULL;
200 view_params.hwndView = NULL;
202 hr = IShellView2_CreateViewWindow2(shell_view2, &view_params);
203 if (hr == E_FAIL)
205 win_skip("CreateViewWindow2 is broken on Vista/W2K8\n");
206 goto cleanup;
208 ok(SUCCEEDED(hr), "CreateViewWindow2 returned %#x\n", hr);
209 if (FAILED(hr)) goto cleanup;
211 hr = IShellView2_GetCurrentInfo(shell_view2, &folder_settings);
212 ok(SUCCEEDED(hr), "GetCurrentInfo returned %#x\n", hr);
213 ok(folder_settings.ViewMode == FVM_LIST,
214 "view mode is %d, expected FVM_LIST\n",
215 folder_settings.ViewMode);
217 hr = IShellView2_DestroyViewWindow(shell_view2);
218 ok(SUCCEEDED(hr), "DestroyViewWindow returned %#x\n", hr);
220 /* XP and W2K3 need this. On W2K the call to DestroyWindow() fails and has
221 * no side effects. NT4 doesn't get here. (FIXME: Vista doesn't get here yet).
223 DestroyWindow(view_params.hwndView);
225 view_params.pvid = &VID_Details;
226 hr = IShellView2_CreateViewWindow2(shell_view2, &view_params);
227 ok(SUCCEEDED(hr), "CreateViewWindow2 returned %#x\n", hr);
228 if (FAILED(hr)) goto cleanup;
230 hr = IShellView2_GetCurrentInfo(shell_view2, &folder_settings);
231 ok(SUCCEEDED(hr), "GetCurrentInfo returned %#x\n", hr);
232 ok(folder_settings.ViewMode == FVM_DETAILS || broken(folder_settings.ViewMode == FVM_LIST), /* nt4 */
233 "view mode is %d, expected FVM_DETAILS\n",
234 folder_settings.ViewMode);
236 cleanup:
237 if (shell_view2) IShellView2_Release(shell_view2);
238 if (shell_view) IShellView_Release(shell_view);
239 PostMessageA(GetParent(dlg), WM_COMMAND, IDCANCEL, 0);
242 return 0;
245 static UINT_PTR WINAPI template_hook(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
247 if (msg == WM_INITDIALOG)
249 HWND p,cb;
250 INT sel;
251 p = GetParent(dlg);
252 ok(p!=NULL, "Failed to get parent of template\n");
253 cb = GetDlgItem(p,0x470);
254 ok(cb!=NULL, "Failed to get filter combobox\n");
255 sel = SendMessageA(cb, CB_GETCURSEL, 0, 0);
256 ok (sel != -1, "Failed to get selection from filter listbox\n");
258 if (msg == WM_NOTIFY)
260 if (((LPNMHDR)lParam)->code == CDN_FOLDERCHANGE)
261 PostMessageA(GetParent(dlg), WM_COMMAND, IDCANCEL, 0);
263 return 0;
266 static void test_create_view_window2(void)
268 OPENFILENAMEA ofn = {0};
269 char filename[1024] = {0};
270 DWORD ret;
272 ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
273 ofn.lpstrFile = filename;
274 ofn.nMaxFile = 1024;
275 ofn.lpfnHook = create_view_window2_hook;
276 ofn.Flags = OFN_ENABLEHOOK | OFN_EXPLORER;
277 ret = GetOpenFileNameA(&ofn);
278 ok(!ret, "GetOpenFileNameA returned %#x\n", ret);
279 ret = CommDlgExtendedError();
280 ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
283 static void test_create_view_template(void)
285 OPENFILENAMEA ofn = {0};
286 char filename[1024] = {0};
287 DWORD ret;
289 ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
290 ofn.lpstrFile = filename;
291 ofn.nMaxFile = 1024;
292 ofn.lpfnHook = template_hook;
293 ofn.Flags = OFN_ENABLEHOOK | OFN_EXPLORER| OFN_ENABLETEMPLATE;
294 ofn.hInstance = GetModuleHandleA(NULL);
295 ofn.lpTemplateName = "template1";
296 ofn.lpstrFilter="text\0*.txt\0All\0*\0\0";
297 ret = GetOpenFileNameA(&ofn);
298 ok(!ret, "GetOpenFileNameA returned %#x\n", ret);
299 ret = CommDlgExtendedError();
300 ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
303 /* test cases for resizing of the file dialog */
304 static const struct {
305 DWORD flags;
306 int resize_folderchange;/* change in CDN_FOLDERCHANGE handler */
307 int resize_timer1; /* change in first WM_TIMER handler */
308 int resize_check; /* expected change (in second WM_TIMER handler) */
309 BOOL todo; /* mark that test todo_wine */
310 BOOL testcontrols; /* test resizing and moving of the controls */
311 } resize_testcases[] = {
312 { 0 , 10, 10, 20,FALSE,FALSE}, /* 0 */
313 { 0 ,-10,-10,-20,FALSE,FALSE},
314 { OFN_ENABLESIZING , 0, 0, 0,FALSE,FALSE},
315 { OFN_ENABLESIZING , 0,-10, 0,FALSE,FALSE},
316 { OFN_ENABLESIZING , 0, 10, 10,FALSE, TRUE},
317 { OFN_ENABLESIZING ,-10, 0, 10,FALSE,FALSE}, /* 5 */
318 { OFN_ENABLESIZING , 10, 0, 10,FALSE,FALSE},
319 { OFN_ENABLESIZING , 0, 10, 20,FALSE,FALSE},
320 /* mark the end */
321 { 0xffffffff }
324 static UINT_PTR WINAPI resize_template_hook(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
326 static RECT initrc, rc;
327 static int index, count;
328 static BOOL gotSWP_bottom, gotShowWindow;
329 HWND parent = GetParent( dlg);
330 int resize;
331 #define MAXNRCTRLS 30
332 static RECT ctrlrcs[MAXNRCTRLS];
333 static int ctrlids[MAXNRCTRLS];
334 static HWND ctrls[MAXNRCTRLS];
335 static int nrctrls;
337 switch( msg)
339 case WM_INITDIALOG:
341 DWORD style;
343 index = ((OPENFILENAMEA*)lParam)->lCustData;
344 count = 0;
345 gotSWP_bottom = gotShowWindow = FALSE;
346 /* test style */
347 style = GetWindowLongA( parent, GWL_STYLE);
348 if( resize_testcases[index].flags & OFN_ENABLESIZING)
349 if( !(style & WS_SIZEBOX)) {
350 win_skip( "OFN_ENABLESIZING flag not supported.\n");
351 resizesupported = FALSE;
352 PostMessageA( parent, WM_COMMAND, IDCANCEL, 0);
353 } else
354 ok( style & WS_SIZEBOX,
355 "testid %d: dialog should have a WS_SIZEBOX style.\n", index);
356 else
357 ok( !(style & WS_SIZEBOX),
358 "testid %d: dialog should not have a WS_SIZEBOX style.\n", index);
359 break;
361 case WM_NOTIFY:
363 if(( (LPNMHDR)lParam)->code == CDN_FOLDERCHANGE){
364 GetWindowRect( parent, &initrc);
365 if( (resize = resize_testcases[index].resize_folderchange)){
366 MoveWindow( parent, initrc.left,initrc.top, initrc.right - initrc.left + resize,
367 initrc.bottom - initrc.top + resize, TRUE);
369 SetTimer( dlg, 0, 100, 0);
371 break;
373 case WM_TIMER:
375 if( count == 0){
376 /* store the control rectangles */
377 if( resize_testcases[index].testcontrols) {
378 HWND ctrl;
379 int i;
380 for( i = 0, ctrl = GetWindow( parent, GW_CHILD);
381 i < MAXNRCTRLS && ctrl;
382 i++, ctrl = GetWindow( ctrl, GW_HWNDNEXT)) {
383 ctrlids[i] = GetDlgCtrlID( ctrl);
384 GetWindowRect( ctrl, &ctrlrcs[i]);
385 MapWindowPoints( NULL, parent, (LPPOINT) &ctrlrcs[i], 2);
386 ctrls[i] = ctrl;
388 nrctrls = i;
390 if( (resize = resize_testcases[index].resize_timer1)){
391 GetWindowRect( parent, &rc);
392 MoveWindow( parent, rc.left,rc.top, rc.right - rc.left + resize,
393 rc.bottom - rc.top + resize, TRUE);
395 } else if( count == 1){
396 resize = resize_testcases[index].resize_check;
397 GetWindowRect( parent, &rc);
398 if( resize_testcases[index].todo){
399 todo_wine {
400 ok( resize == rc.right - rc.left - initrc.right + initrc.left,
401 "testid %d size-x change %d expected %d\n", index,
402 rc.right - rc.left - initrc.right + initrc.left, resize);
403 ok( resize == rc.bottom - rc.top - initrc.bottom + initrc.top,
404 "testid %d size-y change %d expected %d\n", index,
405 rc.bottom - rc.top - initrc.bottom + initrc.top, resize);
407 }else{
408 ok( resize == rc.right - rc.left - initrc.right + initrc.left,
409 "testid %d size-x change %d expected %d\n", index,
410 rc.right - rc.left - initrc.right + initrc.left, resize);
411 ok( resize == rc.bottom - rc.top - initrc.bottom + initrc.top,
412 "testid %d size-y change %d expected %d\n", index,
413 rc.bottom - rc.top - initrc.bottom + initrc.top, resize);
415 if( resize_testcases[index].testcontrols) {
416 int i;
417 RECT rc;
418 for( i = 0; i < nrctrls; i++) {
419 GetWindowRect( ctrls[i], &rc);
420 MapWindowPoints( NULL, parent, (LPPOINT) &rc, 2);
421 switch( ctrlids[i]){
423 /* test if RECT R1, moved and sized result in R2 */
424 #define TESTRECTS( R1, R2, Mx, My, Sx, Sy) \
425 ((R1).left + (Mx) ==(R2).left \
426 &&(R1).top + (My) ==(R2).top \
427 &&(R1).right + (Mx) + (Sx) == (R2).right \
428 &&(R1).bottom + (My) + (Sy) ==(R2).bottom)
430 /* sized horizontal and moved vertical */
431 case cmb1:
432 case edt1:
433 ok( TESTRECTS( ctrlrcs[i], rc, 0, 10, 10, 0),
434 "control id %03x should have sized horizontally and moved vertically, before %d,%d-%d,%d after %d,%d-%d,%d\n",
435 ctrlids[i], ctrlrcs[i].left, ctrlrcs[i].top,
436 ctrlrcs[i].right, ctrlrcs[i].bottom,
437 rc.left, rc.top, rc.right, rc.bottom);
438 break;
439 /* sized horizontal and vertical */
440 case lst2:
441 ok( TESTRECTS( ctrlrcs[i], rc, 0, 0, 10, 10),
442 "control id %03x should have sized horizontally and vertically, before %d,%d-%d,%d after %d,%d-%d,%d\n",
443 ctrlids[i], ctrlrcs[i].left, ctrlrcs[i].top,
444 ctrlrcs[i].right, ctrlrcs[i].bottom,
445 rc.left, rc.top, rc.right, rc.bottom);
446 break;
447 /* moved horizontal and vertical */
448 case IDCANCEL:
449 case pshHelp:
450 ok( TESTRECTS( ctrlrcs[i], rc, 10, 10, 0, 0),
451 "control id %03x should have moved horizontally and vertically, before %d,%d-%d,%d after %d,%d-%d,%d\n",
452 ctrlids[i], ctrlrcs[i].left, ctrlrcs[i].top,
453 ctrlrcs[i].right, ctrlrcs[i].bottom,
454 rc.left, rc.top, rc.right, rc.bottom);
455 break;
456 /* moved vertically */
457 case chx1:
458 case stc2:
459 case stc3:
460 ok( TESTRECTS( ctrlrcs[i], rc, 0, 10, 0, 0),
461 "control id %03x should have moved vertically, before %d,%d-%d,%d after %d,%d-%d,%d\n",
462 ctrlids[i], ctrlrcs[i].left, ctrlrcs[i].top,
463 ctrlrcs[i].right, ctrlrcs[i].bottom,
464 rc.left, rc.top, rc.right, rc.bottom);
465 break;
466 /* resized horizontal */
467 case cmb2: /* aka IDC_LOOKIN */
468 ok( TESTRECTS( ctrlrcs[i], rc, 0, 0, 10, 0)||
469 TESTRECTS( ctrlrcs[i], rc, 0, 0, 0, 0), /* Vista and higher */
470 "control id %03x should have resized horizontally, before %d,%d-%d,%d after %d,%d-%d,%d\n",
471 ctrlids[i], ctrlrcs[i].left, ctrlrcs[i].top,
472 ctrlrcs[i].right, ctrlrcs[i].bottom,
473 rc.left, rc.top, rc.right, rc.bottom);
474 break;
475 /* non moving non sizing controls */
476 case stc4:
477 ok( TESTRECTS( rc, ctrlrcs[i], 0, 0, 0, 0),
478 "control id %03x was moved/resized, before %d,%d-%d,%d after %d,%d-%d,%d\n",
479 ctrlids[i], ctrlrcs[i].left, ctrlrcs[i].top,
480 ctrlrcs[i].right, ctrlrcs[i].bottom,
481 rc.left, rc.top, rc.right, rc.bottom);
482 break;
483 /* todo_wine: non moving non sizing controls */
484 case lst1:
485 todo_wine
486 ok( TESTRECTS( rc, ctrlrcs[i], 0, 0, 0, 0),
487 "control id %03x was moved/resized, before %d,%d-%d,%d after %d,%d-%d,%d\n",
488 ctrlids[i], ctrlrcs[i].left, ctrlrcs[i].top,
489 ctrlrcs[i].right, ctrlrcs[i].bottom,
490 rc.left, rc.top, rc.right, rc.bottom);
491 break;
492 /* don't test: id is not unique */
493 case IDOK:
494 case stc1:
495 case 0:
496 case -1:
497 break;
498 default:
499 trace("untested control id %03x before %d,%d-%d,%d after %d,%d-%d,%d\n",
500 ctrlids[i], ctrlrcs[i].left, ctrlrcs[i].top,
501 ctrlrcs[i].right, ctrlrcs[i].bottom,
502 rc.left, rc.top, rc.right, rc.bottom);
503 #undef TESTRECTS
504 #undef MAXNRCTRLS
508 KillTimer( dlg, 0);
509 PostMessageA( parent, WM_COMMAND, IDCANCEL, 0);
511 count++;
513 break;
514 case WM_WINDOWPOSCHANGING:
516 WINDOWPOS *pwp = (WINDOWPOS *)lParam;
517 if( !index && pwp->hwndInsertAfter == HWND_BOTTOM){
518 gotSWP_bottom = TRUE;
519 ok(!gotShowWindow, "The WM_WINDOWPOSCHANGING message came after a WM_SHOWWINDOW message\n");
522 break;
523 case WM_SHOWWINDOW:
525 if( !index){
526 gotShowWindow = TRUE;
527 ok(gotSWP_bottom, "No WM_WINDOWPOSCHANGING message came before a WM_SHOWWINDOW message\n");
530 break;
532 return 0;
535 static void test_resize(void)
537 OPENFILENAMEA ofn = { OPENFILENAME_SIZE_VERSION_400A };
538 char filename[1024] = {0};
539 DWORD ret;
540 int i;
542 ofn.lpstrFile = filename;
543 ofn.nMaxFile = 1024;
544 ofn.lpfnHook = resize_template_hook;
545 ofn.hInstance = GetModuleHandleA(NULL);
546 ofn.lpTemplateName = "template_sz";
547 for( i = 0; resize_testcases[i].flags != 0xffffffff; i++) {
548 ofn.lCustData = i;
549 ofn.Flags = resize_testcases[i].flags |
550 OFN_ENABLEHOOK | OFN_EXPLORER| OFN_ENABLETEMPLATE | OFN_SHOWHELP ;
551 ret = GetOpenFileNameA(&ofn);
552 ok(!ret, "GetOpenFileName returned %#x\n", ret);
553 ret = CommDlgExtendedError();
554 ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
558 /* test cases for control message IDOK */
559 /* Show case for bug #19079 */
560 typedef struct {
561 int retval; /* return code of the message handler */
562 BOOL setmsgresult; /* set the result in the DWLP_MSGRESULT */
563 BOOL usemsgokstr; /* use the FILEOKSTRING message instead of WM_NOTIFY:CDN_FILEOK */
564 BOOL do_subclass; /* subclass the dialog hook procedure */
565 BOOL expclose; /* is the dialog expected to close ? */
566 BOOL actclose; /* has the dialog actually closed ? */
567 } ok_wndproc_testcase;
569 static ok_wndproc_testcase ok_testcases[] = {
570 { 0, FALSE, FALSE, FALSE, TRUE},
571 { 0, TRUE, FALSE, FALSE, TRUE},
572 { 0, FALSE, FALSE, TRUE, TRUE},
573 { 0, TRUE, FALSE, TRUE, TRUE},
574 { 1, FALSE, FALSE, FALSE, TRUE},
575 { 1, TRUE, FALSE, FALSE, FALSE},
576 { 1, FALSE, FALSE, TRUE, FALSE},
577 { 1, TRUE, FALSE, TRUE, FALSE},
578 /* FILEOKSTRING tests */
579 { 1, TRUE, TRUE, FALSE, FALSE},
580 { 1, FALSE, TRUE, TRUE, FALSE},
581 /* mark the end */
582 { -1 }
585 /* test_ok_wndproc can be used as hook procedure or a subclass
586 * window proc for the file dialog */
587 static UINT_PTR WINAPI test_ok_wndproc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
589 HWND parent = GetParent( dlg);
590 static ok_wndproc_testcase *testcase = NULL;
591 static UINT msgFILEOKSTRING;
592 if (msg == WM_INITDIALOG)
594 testcase = (ok_wndproc_testcase*)((OPENFILENAMEA*)lParam)->lCustData;
595 testcase->actclose = TRUE;
596 msgFILEOKSTRING = RegisterWindowMessageA( FILEOKSTRINGA);
598 if( msg == WM_NOTIFY) {
599 if(((LPNMHDR)lParam)->code == CDN_FOLDERCHANGE) {
600 SetTimer( dlg, 0, 100, 0);
601 PostMessageA( parent, WM_COMMAND, IDOK, 0);
602 return FALSE;
603 } else if(((LPNMHDR)lParam)->code == CDN_FILEOK) {
604 if( testcase->usemsgokstr)
605 return FALSE;
606 if( testcase->setmsgresult)
607 SetWindowLongPtrA( dlg, DWLP_MSGRESULT, testcase->retval);
608 return testcase->retval;
611 if( msg == msgFILEOKSTRING) {
612 if( !testcase->usemsgokstr)
613 return FALSE;
614 if( testcase->setmsgresult)
615 SetWindowLongPtrA( dlg, DWLP_MSGRESULT, testcase->retval);
616 return testcase->retval;
618 if( msg == WM_TIMER) {
619 /* the dialog did not close automatically */
620 testcase->actclose = FALSE;
621 KillTimer( dlg, 0);
622 PostMessageA( parent, WM_COMMAND, IDCANCEL, 0);
623 return FALSE;
625 if( testcase && testcase->do_subclass)
626 return DefWindowProcA( dlg, msg, wParam, lParam);
627 return FALSE;
630 static UINT_PTR WINAPI ok_template_hook(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
632 if (msg == WM_SETFONT)
633 SetWindowLongPtrA( dlg, GWLP_WNDPROC, (LONG_PTR) test_ok_wndproc);
634 return FALSE;
637 static void test_ok(void)
639 OPENFILENAMEA ofn = { OPENFILENAME_SIZE_VERSION_400A };
640 char filename[1024] = {0};
641 char tmpfilename[ MAX_PATH];
642 char curdir[MAX_PATH];
643 int i;
644 DWORD ret;
645 BOOL cdret;
647 cdret = GetCurrentDirectoryA(sizeof(curdir), curdir);
648 ok(cdret, "Failed to get current dir err %d\n", GetLastError());
649 if (!GetTempFileNameA(".", "txt", 0, tmpfilename)) {
650 skip("Failed to create a temporary file name\n");
651 return;
653 ofn.lpstrFile = filename;
654 ofn.nMaxFile = 1024;
655 ofn.hInstance = GetModuleHandleA(NULL);
656 ofn.lpTemplateName = "template1";
657 ofn.Flags = OFN_ENABLEHOOK | OFN_EXPLORER| OFN_ENABLETEMPLATE ;
658 for( i = 0; ok_testcases[i].retval != -1; i++) {
659 strcpy( filename, tmpfilename);
660 ofn.lCustData = (LPARAM)(ok_testcases + i);
661 ofn.lpfnHook = ok_testcases[i].do_subclass ? ok_template_hook : test_ok_wndproc;
662 ret = GetOpenFileNameA(&ofn);
663 ok( ok_testcases[i].expclose == ok_testcases[i].actclose,
664 "testid %d: Open File dialog should %shave closed.\n", i,
665 ok_testcases[i].expclose ? "" : "NOT ");
666 ok(ret == ok_testcases[i].expclose, "testid %d: GetOpenFileName returned %#x\n", i, ret);
667 ret = CommDlgExtendedError();
668 ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
669 cdret = SetCurrentDirectoryA(curdir);
670 ok(cdret, "Failed to restore current dir err %d\n", GetLastError());
672 ret = DeleteFileA( tmpfilename);
673 ok( ret, "Failed to delete temporary file %s err %d\n", tmpfilename, GetLastError());
676 /* test arranging with a custom template */
677 typedef struct {
678 int x, y; /* left, top coordinates */
679 int cx, cy; /* width and height */
680 } posz;
681 static struct {
682 int nrcontrols; /* 0: no controls, 1: just the stc32 control 2: with button */
683 posz poszDlg;
684 posz poszStc32;
685 posz poszBtn;
686 DWORD ofnflags;
687 } arrange_tests[] = {
688 /* do not change the first two cases: used to get the uncustomized sizes */
689 { 0, {0},{0},{0},0 },
690 { 0, {0},{0},{0}, OFN_SHOWHELP},
691 /* two tests with just a subdialog, no controls */
692 { 0, {0, 0, 316, 76},{0},{0},0 },
693 { 0, {0, 0, 100, 76},{0},{0}, OFN_SHOWHELP},
694 /* now with a control with id stc32 */
695 { 1, {0, 0, 316, 76} ,{0, 0, 204, 76,},{0},0 }, /* bug #17748*/
696 { 1, {0, 0, 316, 76} ,{0, 0, 204, 76,},{0}, OFN_SHOWHELP}, /* bug #17748*/
697 /* tests with size of the stc32 control higher or wider then the standard dialog */
698 { 1, {0, 0, 316, 170} ,{0, 0, 204, 170,},{0},0 },
699 { 1, {0, 0, 316, 165} ,{0, 0, 411, 165,},{0}, OFN_SHOWHELP },
700 /* move the stc32 control around */
701 { 1, {0, 0, 300, 100} ,{73, 17, 50, 50,},{0},0 },
702 /* add control */
703 { 2, {0, 0, 280, 100} ,{0, 0, 50, 50,},{300,20,30,30},0 },
704 /* enable resizing should make the dialog bigger */
705 { 0, {0},{0},{0}, OFN_SHOWHELP|OFN_ENABLESIZING},
706 /* mark the end */
707 { -1 }
710 static UINT_PTR WINAPI template_hook_arrange(HWND dlgChild, UINT msg, WPARAM wParam, LPARAM lParam)
712 static int index, fixhelp;
713 static posz posz0[2];
714 static RECT clrcParent, clrcChild, rcStc32;
715 static HWND hwndStc32;
716 HWND dlgParent;
718 dlgParent = GetParent( dlgChild);
719 if (msg == WM_INITDIALOG) {
720 index = ((OPENFILENAMEA*)lParam)->lCustData;
721 /* get the positions before rearrangement */
722 GetClientRect( dlgParent, &clrcParent);
723 GetClientRect( dlgChild, &clrcChild);
724 hwndStc32 = GetDlgItem( dlgChild, stc32);
725 if( hwndStc32) GetWindowRect( hwndStc32, &rcStc32);
727 if (msg == WM_NOTIFY && ((LPNMHDR)lParam)->code == CDN_FOLDERCHANGE) {
728 RECT wrcParent;
730 GetWindowRect( dlgParent, &wrcParent);
731 /* the fist two "tests" just save the dialogs position, with and without
732 * help button */
733 if( index == 0) {
734 posz0[0].x = wrcParent.left;
735 posz0[0].y = wrcParent.top;
736 posz0[0].cx = wrcParent.right - wrcParent.left;
737 posz0[0].cy = wrcParent.bottom - wrcParent.top;
738 } else if( index == 1) {
739 posz0[1].x = wrcParent.left;
740 posz0[1].y = wrcParent.top;
741 posz0[1].cx = wrcParent.right - wrcParent.left;
742 posz0[1].cy = wrcParent.bottom - wrcParent.top;
743 fixhelp = posz0[1].cy - posz0[0].cy;
744 } else {
745 /* the real tests */
746 int withhelp;
747 int expectx, expecty;
748 DWORD style;
750 withhelp = (arrange_tests[index].ofnflags & OFN_SHOWHELP) != 0;
751 GetWindowRect( dlgParent, &wrcParent);
752 if( !hwndStc32) {
753 /* case with no custom subitem with stc32:
754 * default to all custom controls below the standard */
755 expecty = posz0[withhelp].cy + clrcChild.bottom;
756 expectx = posz0[withhelp].cx;
757 } else {
758 /* special case: there is a control with id stc32 */
759 /* expected height */
760 expecty = posz0[withhelp].cy;
761 if( rcStc32.bottom - rcStc32.top + (withhelp ? 0 : fixhelp) > clrcParent.bottom) {
762 expecty += clrcChild.bottom - clrcParent.bottom;
763 if( !withhelp) expecty += fixhelp;
765 else
766 expecty += clrcChild.bottom - ( rcStc32.bottom - rcStc32.top) ;
767 /* expected width */
768 expectx = posz0[withhelp].cx;
769 if( rcStc32.right - rcStc32.left > clrcParent.right) {
770 expectx += clrcChild.right - clrcParent.right;
772 else
773 expectx += clrcChild.right - ( rcStc32.right - rcStc32.left) ;
775 style = GetWindowLongA( dlgParent, GWL_STYLE);
776 if( !(style & WS_SIZEBOX)) {
777 /* without the OFN_ENABLESIZING flag */
778 ok( wrcParent.bottom - wrcParent.top == expecty,
779 "Wrong height of dialog %d, expected %d\n",
780 wrcParent.bottom - wrcParent.top, expecty);
781 ok( wrcParent.right - wrcParent.left == expectx,
782 "Wrong width of dialog %d, expected %d\n",
783 wrcParent.right - wrcParent.left, expectx);
784 } else todo_wine {
785 /* with the OFN_ENABLESIZING flag */
786 ok( wrcParent.bottom - wrcParent.top > expecty,
787 "Wrong height of dialog %d, expected more than %d\n",
788 wrcParent.bottom - wrcParent.top, expecty);
789 ok( wrcParent.right - wrcParent.left > expectx,
790 "Wrong width of dialog %d, expected more than %d\n",
791 wrcParent.right - wrcParent.left, expectx);
795 PostMessageA( dlgParent, WM_COMMAND, IDCANCEL, 0);
797 return 0;
800 static void test_arrange(void)
802 OPENFILENAMEA ofn = {0};
803 char filename[1024] = {0};
804 DWORD ret;
805 HRSRC hRes;
806 HANDLE hDlgTmpl;
807 LPBYTE pv;
808 DLGTEMPLATE *template;
809 DLGITEMTEMPLATE *itemtemplateStc32, *itemtemplateBtn;
810 int i;
812 /* load subdialog template into memory */
813 hRes = FindResourceA( GetModuleHandleA(NULL), "template_stc32", (LPSTR)RT_DIALOG);
814 hDlgTmpl = LoadResource( GetModuleHandleA(NULL), hRes );
815 /* get pointers to the structures for the dialog and the controls */
816 pv = LockResource( hDlgTmpl );
817 template = (DLGTEMPLATE*)pv;
818 if( template->x != 11111) {
819 win_skip("could not find the dialog template\n");
820 return;
822 /* skip dialog template, menu, class and title */
823 pv += sizeof(DLGTEMPLATE);
824 pv += 3 * sizeof(WORD);
825 /* skip font info */
826 while( *(WORD*)pv)
827 pv += sizeof(WORD);
828 pv += sizeof(WORD);
829 /* align on 32 bit boundaries */
830 pv = (LPBYTE)(((UINT_PTR)pv + 3 ) & ~3);
831 itemtemplateStc32 = (DLGITEMTEMPLATE*)pv;
832 if( itemtemplateStc32->x != 22222) {
833 win_skip("could not find the first item template\n");
834 return;
836 /* skip itemtemplate, class, title and creation data */
837 pv += sizeof(DLGITEMTEMPLATE);
838 pv += 4 * sizeof(WORD);
839 /* align on 32 bit boundaries */
840 pv = (LPBYTE)(((UINT_PTR)pv + 3 ) & ~3);
841 itemtemplateBtn = (DLGITEMTEMPLATE*)pv;
842 if( itemtemplateBtn->x != 12345) {
843 win_skip("could not find the second item template\n");
844 return;
847 ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
848 ofn.lpstrFile = filename;
849 ofn.nMaxFile = 1024;
850 ofn.lpfnHook = template_hook_arrange;
851 ofn.hInstance = hDlgTmpl;
852 ofn.lpstrFilter="text\0*.txt\0All\0*\0\0";
853 for( i = 0; arrange_tests[i].nrcontrols != -1; i++) {
854 ofn.lCustData = i;
855 ofn.Flags = OFN_ENABLEHOOK | OFN_EXPLORER| OFN_ENABLETEMPLATEHANDLE | OFN_HIDEREADONLY |
856 arrange_tests[i].ofnflags;
857 template->cdit = arrange_tests[i].nrcontrols;
858 template->x = arrange_tests[i].poszDlg.x;
859 template->y = arrange_tests[i].poszDlg.y;
860 template->cx = arrange_tests[i].poszDlg.cx;
861 template->cy = arrange_tests[i].poszDlg.cy;
862 itemtemplateStc32->x = arrange_tests[i].poszStc32.x;
863 itemtemplateStc32->y = arrange_tests[i].poszStc32.y;
864 itemtemplateStc32->cx = arrange_tests[i].poszStc32.cx;
865 itemtemplateStc32->cy = arrange_tests[i].poszStc32.cy;
866 itemtemplateBtn->x = arrange_tests[i].poszBtn.x;
867 itemtemplateBtn->y = arrange_tests[i].poszBtn.y;
868 itemtemplateBtn->cx = arrange_tests[i].poszBtn.cx;
869 itemtemplateBtn->cy = arrange_tests[i].poszBtn.cy;
870 ret = GetOpenFileNameA(&ofn);
871 ok(!ret, "GetOpenFileNameA returned %#x\n", ret);
872 ret = CommDlgExtendedError();
873 ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
877 static CHAR SYSDIR[MAX_PATH];
879 static UINT_PTR CALLBACK path_hook_proc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
881 LPNMHDR nmh;
883 if( msg == WM_NOTIFY)
885 nmh = (LPNMHDR) lParam;
886 if( nmh->code == CDN_INITDONE)
888 PostMessageA( GetParent(hDlg), WM_COMMAND, IDCANCEL, FALSE);
890 else if ( nmh->code == CDN_FOLDERCHANGE)
892 char buf[1024];
893 int ret;
895 memset(buf, 0x66, sizeof(buf));
896 ret = SendMessageA( GetParent(hDlg), CDM_GETFOLDERPATH, sizeof(buf), (LPARAM)buf);
897 ok(!lstrcmpiA(SYSDIR, buf), "Expected '%s', got '%s'\n", SYSDIR, buf);
898 ok(lstrlenA(SYSDIR) + 1 == ret, "Expected %d, got %d\n", lstrlenA(SYSDIR) + 1, ret);
902 return 0;
905 static void test_getfolderpath(void)
907 OPENFILENAMEA ofn;
908 BOOL result;
909 char szFileName[MAX_PATH] = "";
910 char szInitialDir[MAX_PATH];
912 /* We need to pick a different directory as the other tests because of new
913 * Windows 7 behavior.
915 GetSystemDirectoryA(szInitialDir, MAX_PATH);
916 lstrcpyA(SYSDIR, szInitialDir);
918 ZeroMemory(&ofn, sizeof(ofn));
920 ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
921 ofn.hwndOwner = NULL;
922 ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
923 ofn.lpstrFile = szFileName;
924 ofn.nMaxFile = MAX_PATH;
925 ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLEHOOK;
926 ofn.lpstrDefExt = "txt";
927 ofn.lpfnHook = path_hook_proc;
928 ofn.lpstrInitialDir = szInitialDir;
930 result = GetOpenFileNameA(&ofn);
931 ok(FALSE == result, "expected FALSE, got %d\n", result);
932 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
933 CommDlgExtendedError());
935 result = GetSaveFileNameA(&ofn);
936 ok(FALSE == result, "expected FALSE, got %d\n", result);
937 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
938 CommDlgExtendedError());
941 static void test_resizable2(void)
943 OPENFILENAMEA ofn = {0};
944 char filename[1024] = "pls press Enter if sizable, Esc otherwise";
945 DWORD ret;
947 /* interactive because there is no hook function */
948 if( !winetest_interactive) {
949 skip( "some interactive resizable dialog tests (set WINETEST_INTERACTIVE=1)\n");
950 return;
952 ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
953 ofn.lpstrFile = filename;
954 ofn.nMaxFile = 1024;
955 ofn.lpfnHook = NULL;
956 ofn.hInstance = GetModuleHandleA(NULL);
957 ofn.lpTemplateName = "template1";
958 ofn.Flags = OFN_EXPLORER;
959 #define ISSIZABLE TRUE
960 ret = GetOpenFileNameA(&ofn);
961 ok( ret == ISSIZABLE, "File Dialog should have been sizable\n");
962 ret = CommDlgExtendedError();
963 ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
964 ofn.Flags = OFN_EXPLORER | OFN_ENABLETEMPLATE;
965 ret = GetOpenFileNameA(&ofn);
966 ok( ret != ISSIZABLE, "File Dialog should NOT have been sizable\n");
967 ret = CommDlgExtendedError();
968 ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
969 ofn.Flags = OFN_EXPLORER | OFN_ENABLETEMPLATEHANDLE;
970 ofn.hInstance = LoadResource( GetModuleHandleA(NULL), FindResourceA( GetModuleHandleA(NULL), "template1", (LPSTR)RT_DIALOG));
971 ofn.lpTemplateName = NULL;
972 ret = GetOpenFileNameA(&ofn);
973 ok( ret != ISSIZABLE, "File Dialog should NOT have been sizable\n");
974 ret = CommDlgExtendedError();
975 ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
976 ofn.Flags = OFN_EXPLORER | OFN_ENABLEHOOK;
977 ret = GetOpenFileNameA(&ofn);
978 ok( ret != ISSIZABLE, "File Dialog should NOT have been sizable\n");
979 ret = CommDlgExtendedError();
980 ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
981 #undef ISSIZABLE
984 static void test_mru(void)
986 ok_wndproc_testcase testcase = {0};
987 OPENFILENAMEA ofn = { OPENFILENAME_SIZE_VERSION_400A };
988 const char *test_dir_name = "C:\\mru_test";
989 const char *test_file_name = "test.txt";
990 const char *test_full_path = "C:\\mru_test\\test.txt";
991 char filename_buf[MAX_PATH];
992 DWORD ret;
994 ofn.lpstrFile = filename_buf;
995 ofn.nMaxFile = sizeof(filename_buf);
996 ofn.lpTemplateName = "template1";
997 ofn.hInstance = GetModuleHandleA(NULL);
998 ofn.Flags = OFN_ENABLEHOOK | OFN_EXPLORER | OFN_ENABLETEMPLATE | OFN_NOCHANGEDIR;
999 ofn.lCustData = (LPARAM)&testcase;
1000 ofn.lpfnHook = test_ok_wndproc;
1002 SetLastError(0xdeadbeef);
1003 ret = CreateDirectoryA(test_dir_name, NULL);
1004 ok(ret == TRUE, "CreateDirectoryA should have succeeded: %d\n", GetLastError());
1006 /* "teach" comdlg32 about this directory */
1007 strcpy(filename_buf, test_full_path);
1008 SetLastError(0xdeadbeef);
1009 ret = GetOpenFileNameA(&ofn);
1010 ok(ret, "GetOpenFileNameA should have succeeded: %d\n", GetLastError());
1011 ret = CommDlgExtendedError();
1012 ok(!ret, "CommDlgExtendedError returned %x\n", ret);
1013 ok(testcase.actclose, "Open File dialog should have closed.\n");
1014 ok(!strcmp(ofn.lpstrFile, test_full_path), "Expected to get %s, got %s\n", test_full_path, ofn.lpstrFile);
1016 /* get a filename without a full path. it should return the file in
1017 * test_dir_name, not in the CWD */
1018 strcpy(filename_buf, test_file_name);
1019 SetLastError(0xdeadbeef);
1020 ret = GetOpenFileNameA(&ofn);
1021 ok(ret, "GetOpenFileNameA should have succeeded: %d\n", GetLastError());
1022 ret = CommDlgExtendedError();
1023 ok(!ret, "CommDlgExtendedError returned %x\n", ret);
1024 ok(testcase.actclose, "Open File dialog should have closed.\n");
1025 if(strcmp(ofn.lpstrFile, test_full_path) != 0)
1026 win_skip("Platform doesn't save MRU data\n");
1028 SetLastError(0xdeadbeef);
1029 ret = RemoveDirectoryA(test_dir_name);
1030 ok(ret == TRUE, "RemoveDirectoryA should have succeeded: %d\n", GetLastError());
1033 static UINT_PTR WINAPI test_extension_wndproc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
1035 HWND parent = GetParent( dlg);
1036 if( msg == WM_NOTIFY) {
1037 SetTimer( dlg, 0, 1000, 0);
1038 PostMessageA( parent, WM_COMMAND, IDOK, 0);
1040 if( msg == WM_TIMER) {
1041 /* the dialog did not close automatically */
1042 KillTimer( dlg, 0);
1043 PostMessageA( parent, WM_COMMAND, IDCANCEL, 0);
1045 return FALSE;
1048 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
1050 static void test_extension_helper(OPENFILENAMEA* ofn, const char *filter,
1051 const char *expected_filename)
1053 char *filename_ptr;
1054 DWORD ret;
1055 BOOL boolret;
1057 strcpy(ofn->lpstrFile, "deadbeef");
1058 ofn->lpstrFilter = filter;
1060 boolret = GetSaveFileNameA(ofn);
1061 ok(boolret, "%s: expected TRUE\n", filter);
1063 ret = CommDlgExtendedError();
1064 ok(!ret, "%s: CommDlgExtendedError returned %#x\n", filter, ret);
1066 filename_ptr = ofn->lpstrFile + ofn->nFileOffset;
1067 ok(strcmp(filename_ptr, expected_filename) == 0,
1068 "%s: Filename is %s, expected %s\n", filter, filename_ptr, expected_filename);
1071 static void test_extension(void)
1073 OPENFILENAMEA ofn = { OPENFILENAME_SIZE_VERSION_400A };
1074 char filename[1024] = {0};
1075 char curdir[MAX_PATH];
1076 unsigned int i;
1077 BOOL boolret;
1079 const char *defext_concrete_filters[] = {
1080 "TestFilter (*.abc)\0*.abc\0",
1081 "TestFilter (*.abc;)\0*.abc;\0",
1082 "TestFilter (*.abc;*.def)\0*.abc;*.def\0",
1085 const char *defext_wildcard_filters[] = {
1086 "TestFilter (*.pt*)\0*.pt*\0",
1087 "TestFilter (*.pt*;*.abc)\0*.pt*;*.abc\0",
1088 "TestFilter (*.ab?)\0*.ab?\0",
1089 "TestFilter (*.*)\0*.*\0",
1090 "TestFilter (*sav)\0*sav\0",
1091 NULL /* is a test, not an endmark! */
1094 boolret = GetCurrentDirectoryA(sizeof(curdir), curdir);
1095 ok(boolret, "Failed to get current dir err %d\n", GetLastError());
1097 ofn.hwndOwner = NULL;
1098 ofn.lpstrFile = filename;
1099 ofn.nMaxFile = MAX_PATH;
1100 ofn.Flags = OFN_EXPLORER | OFN_ENABLEHOOK;
1101 ofn.lpstrInitialDir = curdir;
1102 ofn.lpfnHook = test_extension_wndproc;
1103 ofn.nFileExtension = 0;
1105 ofn.lpstrDefExt = NULL;
1107 /* Without lpstrDefExt, append no extension */
1108 test_extension_helper(&ofn, "TestFilter (*.abc) lpstrDefExt=NULL\0*.abc\0", "deadbeef");
1109 test_extension_helper(&ofn, "TestFilter (*.ab?) lpstrDefExt=NULL\0*.ab?\0", "deadbeef");
1111 ofn.lpstrDefExt = "";
1113 /* If lpstrDefExt="" and the filter has a concrete extension, append it */
1114 test_extension_helper(&ofn, "TestFilter (*.abc) lpstrDefExt=\"\"\0*.abc\0", "deadbeef.abc");
1116 /* If lpstrDefExt="" and the filter has a wildcard extension, do nothing */
1117 test_extension_helper(&ofn, "TestFilter (*.ab?) lpstrDefExt=\"\"\0*.ab?\0", "deadbeef");
1119 ofn.lpstrDefExt = "xyz";
1121 /* Append concrete extensions from filters */
1122 for (i = 0; i < ARRAY_SIZE(defext_concrete_filters); i++) {
1123 test_extension_helper(&ofn, defext_concrete_filters[i], "deadbeef.abc");
1126 /* Append nothing from this filter */
1127 test_extension_helper(&ofn, "TestFilter (*.)\0*.\0", "deadbeef");
1129 /* Ignore wildcard extensions in filters */
1130 for (i = 0; i < ARRAY_SIZE(defext_wildcard_filters); i++) {
1131 test_extension_helper(&ofn, defext_wildcard_filters[i], "deadbeef.xyz");
1135 #undef ARRAY_SIZE
1138 static BOOL WINAPI test_null_enum(HWND hwnd, LPARAM lParam)
1140 /* Find the textbox and send a filename so IDOK will work.
1141 If the file textbox is empty IDOK will be ignored */
1142 CHAR className[20];
1143 if(GetClassNameA(hwnd, className, sizeof(className)) > 0 && !strcmp("Edit",className))
1145 SetWindowTextA(hwnd, "testfile");
1146 return FALSE; /* break window enumeration */
1148 return TRUE;
1151 static UINT_PTR WINAPI test_null_wndproc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
1153 HWND parent = GetParent( dlg);
1154 if( msg == WM_NOTIFY) {
1155 SetTimer( dlg, 0, 100, 0);
1156 SetTimer( dlg, 1, 1000, 0);
1157 EnumChildWindows( parent, test_null_enum, 0);
1159 if( msg == WM_TIMER) {
1160 if(!wParam)
1161 PostMessageA( parent, WM_COMMAND, IDOK, 0);
1162 else {
1163 /* the dialog did not close automatically */
1164 KillTimer( dlg, 0);
1165 PostMessageA( parent, WM_COMMAND, IDCANCEL, 0);
1168 return FALSE;
1171 static void test_null_filename(void)
1173 OPENFILENAMEA ofnA = {0};
1174 OPENFILENAMEW ofnW = {0};
1175 WCHAR filterW[] = {'t','e','x','t','\0','*','.','t','x','t','\0',
1176 'A','l','l','\0','*','\0','\0'};
1177 DWORD ret;
1179 ofnA.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
1180 ofnA.lpstrFile = NULL;
1181 ofnA.nMaxFile = 0;
1182 ofnA.nFileOffset = 0xdead;
1183 ofnA.nFileExtension = 0xbeef;
1184 ofnA.lpfnHook = test_null_wndproc;
1185 ofnA.Flags = OFN_ENABLEHOOK | OFN_EXPLORER;
1186 ofnA.hInstance = GetModuleHandleA(NULL);
1187 ofnA.lpstrFilter = "text\0*.txt\0All\0*\0\0";
1188 ofnA.lpstrDefExt = NULL;
1189 ret = GetOpenFileNameA(&ofnA);
1190 todo_wine ok(ret, "GetOpenFileNameA returned %#x\n", ret);
1191 ret = CommDlgExtendedError();
1192 todo_wine ok(!ret, "CommDlgExtendedError returned %#x, should be 0\n", ret);
1194 todo_wine ok(ofnA.nFileOffset != 0xdead, "ofnA.nFileOffset is 0xdead\n");
1195 todo_wine ok(ofnA.nFileExtension != 0xbeef, "ofnA.nFileExtension is 0xbeef\n");
1197 ofnA.lpstrFile = NULL;
1198 ofnA.nMaxFile = 1024; /* bogus input - lpstrFile = NULL but fake 1024 bytes available */
1199 ofnA.nFileOffset = 0xdead;
1200 ofnA.nFileExtension = 0xbeef;
1201 ret = GetOpenFileNameA(&ofnA);
1202 ok(ret, "GetOpenFileNameA returned %#x\n", ret);
1203 ret = CommDlgExtendedError();
1204 ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
1206 ok(ofnA.nFileOffset != 0xdead, "ofnA.nFileOffset is 0xdead\n");
1207 ok(ofnA.nFileExtension == 0, "ofnA.nFileExtension is 0x%x, should be 0\n", ofnA.nFileExtension);
1209 /* unicode tests */
1210 ofnW.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
1211 ofnW.lpstrFile = NULL;
1212 ofnW.nMaxFile = 0;
1213 ofnW.nFileOffset = 0xdead;
1214 ofnW.nFileExtension = 0xbeef;
1215 ofnW.lpfnHook = test_null_wndproc;
1216 ofnW.Flags = OFN_ENABLEHOOK | OFN_EXPLORER;
1217 ofnW.hInstance = GetModuleHandleW(NULL);
1218 ofnW.lpstrFilter = filterW;
1219 ofnW.lpstrDefExt = NULL;
1220 ret = GetOpenFileNameW(&ofnW);
1221 todo_wine ok(ret, "GetOpenFileNameW returned %#x\n", ret);
1222 ret = CommDlgExtendedError();
1223 todo_wine ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
1225 todo_wine ok(ofnW.nFileOffset != 0xdead, "ofnW.nFileOffset is 0xdead\n");
1226 todo_wine ok(ofnW.nFileExtension != 0xbeef, "ofnW.nFileExtension is 0xbeef\n");
1228 ofnW.lpstrFile = NULL;
1229 ofnW.nMaxFile = 1024; /* bogus input - lpstrFile = NULL but fake 1024 bytes available */
1230 ofnW.nFileOffset = 0xdead;
1231 ofnW.nFileExtension = 0xbeef;
1232 ret = GetOpenFileNameW(&ofnW);
1233 ok(ret, "GetOpenFileNameA returned %#x\n", ret);
1234 ret = CommDlgExtendedError();
1235 ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
1237 ok(ofnW.nFileOffset != 0xdead, "ofnW.nFileOffset is 0xdead\n");
1238 ok(ofnW.nFileExtension == 0, "ofnW.nFileExtension is 0x%x, should be 0\n", ofnW.nFileExtension);
1241 START_TEST(filedlg)
1243 test_DialogCancel();
1244 test_create_view_window2();
1245 test_create_view_template();
1246 test_arrange();
1247 test_resize();
1248 test_ok();
1249 test_getfolderpath();
1250 test_mru();
1251 if( resizesupported) test_resizable2();
1252 test_extension();
1253 test_null_filename();