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>
24 #define WIN32_NO_STATUS
26 #define COM_NO_WINDOWS_H
28 #include <wine/test.h>
42 static BOOL resizesupported
= TRUE
;
44 static void toolbarcheck( HWND hDlg
)
46 /* test toolbar properties */
53 for( ctrl
= GetWindow( hDlg
, GW_CHILD
);
54 ctrl
; ctrl
= GetWindow( ctrl
, GW_HWNDNEXT
)) {
55 GetClassNameA( ctrl
, classname
, 10);
57 if( !strcmp( classname
, "Toolbar")) break;
59 ok( ctrl
!= NULL
, "could not get the toolbar control\n");
60 ret
= SendMessageA( ctrl
, TB_ADDSTRINGA
, 0, (LPARAM
)"winetestwinetest\0\0");
61 ok( ret
== 0, "addstring returned %d (expected 0)\n", ret
);
62 maxtextrows
= SendMessageA( ctrl
, TB_GETTEXTROWS
, 0, 0);
63 ok( maxtextrows
== 0 || broken(maxtextrows
== 1), /* Win2k and below */
64 "Get(Max)TextRows returned %d (expected 0)\n", maxtextrows
);
68 static UINT_PTR CALLBACK
OFNHookProc( HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
74 nmh
= (LPNMHDR
) lParam
;
75 if( nmh
->code
== CDN_INITDONE
)
77 PostMessageA( GetParent(hDlg
), WM_COMMAND
, IDCANCEL
, FALSE
);
78 } else if (nmh
->code
== CDN_FOLDERCHANGE
)
83 memset(buf
, 0x66, sizeof(buf
));
84 ret
= SendMessageA( GetParent(hDlg
), CDM_GETFOLDERIDLIST
, 5, (LPARAM
)buf
);
85 ok(ret
> 0, "CMD_GETFOLDERIDLIST not implemented\n");
87 ok(buf
[0] == 0x66 && buf
[1] == 0x66, "CMD_GETFOLDERIDLIST: The buffer was touched on failure\n");
88 toolbarcheck( GetParent(hDlg
));
96 static void test_DialogCancel(void)
100 char szFileName
[MAX_PATH
] = "";
101 char szInitialDir
[MAX_PATH
];
103 GetWindowsDirectoryA(szInitialDir
, MAX_PATH
);
105 ZeroMemory(&ofn
, sizeof(ofn
));
107 ofn
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
108 ofn
.hwndOwner
= NULL
;
109 ofn
.lpstrFilter
= "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
110 ofn
.lpstrFile
= szFileName
;
111 ofn
.nMaxFile
= MAX_PATH
;
112 ofn
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_ENABLEHOOK
;
113 ofn
.lpstrDefExt
= "txt";
114 ofn
.lpfnHook
= OFNHookProc
;
115 ofn
.lpstrInitialDir
= szInitialDir
;
118 ok(CDERR_INITIALIZATION
== CommDlgExtendedError(),
119 "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
121 result
= GetOpenFileNameA(&ofn
);
122 ok(FALSE
== result
, "expected FALSE, got %d\n", result
);
123 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
124 CommDlgExtendedError());
127 ok(CDERR_INITIALIZATION
== CommDlgExtendedError(),
128 "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
130 result
= GetSaveFileNameA(&ofn
);
131 ok(FALSE
== result
, "expected FALSE, got %d\n", result
);
132 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
133 CommDlgExtendedError());
136 ok(CDERR_INITIALIZATION
== CommDlgExtendedError(),
137 "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
139 /* Before passing the ofn to Unicode functions, remove the ANSI strings */
140 ofn
.lpstrFilter
= NULL
;
141 ofn
.lpstrInitialDir
= NULL
;
142 ofn
.lpstrDefExt
= NULL
;
145 ok(CDERR_INITIALIZATION
== CommDlgExtendedError(),
146 "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
148 SetLastError(0xdeadbeef);
149 result
= GetOpenFileNameW((LPOPENFILENAMEW
) &ofn
);
150 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
151 win_skip("GetOpenFileNameW is not implemented\n");
154 ok(FALSE
== result
, "expected FALSE, got %d\n", result
);
155 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n", CommDlgExtendedError());
158 SetLastError(0xdeadbeef);
159 result
= GetSaveFileNameW((LPOPENFILENAMEW
) &ofn
);
160 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
161 win_skip("GetSaveFileNameW is not implemented\n");
164 ok(FALSE
== result
, "expected FALSE, got %d\n", result
);
165 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n", CommDlgExtendedError());
169 static UINT_PTR CALLBACK
create_view_window2_hook(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
171 if (msg
== WM_NOTIFY
)
173 if (((LPNMHDR
)lParam
)->code
== CDN_FOLDERCHANGE
)
175 IShellBrowser
*shell_browser
= (IShellBrowser
*)SendMessageA(GetParent(dlg
), WM_USER
+ 7 /* WM_GETISHELLBROWSER */, 0, 0);
176 IShellView
*shell_view
= NULL
;
177 IShellView2
*shell_view2
= NULL
;
178 SV2CVW2_PARAMS view_params
;
179 FOLDERSETTINGS folder_settings
;
181 RECT rect
= {0, 0, 0, 0};
183 hr
= IShellBrowser_QueryActiveShellView(shell_browser
, &shell_view
);
184 ok(SUCCEEDED(hr
), "QueryActiveShellView returned %#x\n", hr
);
185 if (FAILED(hr
)) goto cleanup
;
187 hr
= IShellView_QueryInterface(shell_view
, &IID_IShellView2
, (void **)&shell_view2
);
188 if (hr
== E_NOINTERFACE
)
190 win_skip("IShellView2 not supported\n");
193 ok(SUCCEEDED(hr
), "QueryInterface returned %#x\n", hr
);
194 if (FAILED(hr
)) goto cleanup
;
196 hr
= IShellView2_DestroyViewWindow(shell_view2
);
197 ok(SUCCEEDED(hr
), "DestroyViewWindow returned %#x\n", hr
);
199 folder_settings
.ViewMode
= FVM_LIST
;
200 folder_settings
.fFlags
= 0;
202 view_params
.cbSize
= sizeof(view_params
);
203 view_params
.psvPrev
= NULL
;
204 view_params
.pfs
= &folder_settings
;
205 view_params
.psbOwner
= shell_browser
;
206 view_params
.prcView
= &rect
;
207 view_params
.pvid
= NULL
;
208 view_params
.hwndView
= NULL
;
210 hr
= IShellView2_CreateViewWindow2(shell_view2
, &view_params
);
213 win_skip("CreateViewWindow2 is broken on Vista/W2K8\n");
216 ok(SUCCEEDED(hr
), "CreateViewWindow2 returned %#x\n", hr
);
217 if (FAILED(hr
)) goto cleanup
;
219 hr
= IShellView2_GetCurrentInfo(shell_view2
, &folder_settings
);
220 ok(SUCCEEDED(hr
), "GetCurrentInfo returned %#x\n", hr
);
221 ok(folder_settings
.ViewMode
== FVM_LIST
,
222 "view mode is %d, expected FVM_LIST\n",
223 folder_settings
.ViewMode
);
225 hr
= IShellView2_DestroyViewWindow(shell_view2
);
226 ok(SUCCEEDED(hr
), "DestroyViewWindow returned %#x\n", hr
);
228 /* XP and W2K3 need this. On W2K the call to DestroyWindow() fails and has
229 * no side effects. NT4 doesn't get here. (FIXME: Vista doesn't get here yet).
231 DestroyWindow(view_params
.hwndView
);
233 view_params
.pvid
= &VID_Details
;
234 hr
= IShellView2_CreateViewWindow2(shell_view2
, &view_params
);
235 ok(SUCCEEDED(hr
), "CreateViewWindow2 returned %#x\n", hr
);
236 if (FAILED(hr
)) goto cleanup
;
238 hr
= IShellView2_GetCurrentInfo(shell_view2
, &folder_settings
);
239 ok(SUCCEEDED(hr
), "GetCurrentInfo returned %#x\n", hr
);
240 ok(folder_settings
.ViewMode
== FVM_DETAILS
|| broken(folder_settings
.ViewMode
== FVM_LIST
), /* nt4 */
241 "view mode is %d, expected FVM_DETAILS\n",
242 folder_settings
.ViewMode
);
245 if (shell_view2
) IShellView2_Release(shell_view2
);
246 if (shell_view
) IShellView_Release(shell_view
);
247 PostMessageA(GetParent(dlg
), WM_COMMAND
, IDCANCEL
, 0);
253 static UINT_PTR WINAPI
template_hook(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
255 if (msg
== WM_INITDIALOG
)
260 ok(p
!=NULL
, "Failed to get parent of template\n");
261 cb
= GetDlgItem(p
,0x470);
262 ok(cb
!=NULL
, "Failed to get filter combobox\n");
263 sel
= SendMessageA(cb
, CB_GETCURSEL
, 0, 0);
264 ok (sel
!= -1, "Failed to get selection from filter listbox\n");
266 if (msg
== WM_NOTIFY
)
268 if (((LPNMHDR
)lParam
)->code
== CDN_FOLDERCHANGE
)
269 PostMessageA(GetParent(dlg
), WM_COMMAND
, IDCANCEL
, 0);
274 static void test_create_view_window2(void)
276 OPENFILENAMEA ofn
= {0};
277 char filename
[1024] = {0};
280 ofn
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
281 ofn
.lpstrFile
= filename
;
283 ofn
.lpfnHook
= create_view_window2_hook
;
284 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
;
285 ret
= GetOpenFileNameA(&ofn
);
286 ok(!ret
, "GetOpenFileNameA returned %#x\n", ret
);
287 ret
= CommDlgExtendedError();
288 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
291 static void test_create_view_template(void)
293 OPENFILENAMEA ofn
= {0};
294 char filename
[1024] = {0};
297 ofn
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
298 ofn
.lpstrFile
= filename
;
300 ofn
.lpfnHook
= template_hook
;
301 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
;
302 ofn
.hInstance
= GetModuleHandleA(NULL
);
303 ofn
.lpTemplateName
= "template1";
304 ofn
.lpstrFilter
="text\0*.txt\0All\0*\0\0";
305 ret
= GetOpenFileNameA(&ofn
);
306 ok(!ret
, "GetOpenFileNameA returned %#x\n", ret
);
307 ret
= CommDlgExtendedError();
308 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
311 /* test cases for resizing of the file dialog */
312 static const struct {
314 int resize_folderchange
;/* change in CDN_FOLDERCHANGE handler */
315 int resize_timer1
; /* change in first WM_TIMER handler */
316 int resize_check
; /* expected change (in second WM_TIMER handler) */
317 BOOL todo
; /* mark that test todo_wine */
318 BOOL testcontrols
; /* test resizing and moving of the controls */
319 } resize_testcases
[] = {
320 { 0 , 10, 10, 20,FALSE
,FALSE
}, /* 0 */
321 { 0 ,-10,-10,-20,FALSE
,FALSE
},
322 { OFN_ENABLESIZING
, 0, 0, 0,FALSE
,FALSE
},
323 { OFN_ENABLESIZING
, 0,-10, 0,FALSE
,FALSE
},
324 { OFN_ENABLESIZING
, 0, 10, 10,FALSE
, TRUE
},
325 { OFN_ENABLESIZING
,-10, 0, 10,FALSE
,FALSE
}, /* 5 */
326 { OFN_ENABLESIZING
, 10, 0, 10,FALSE
,FALSE
},
327 { OFN_ENABLESIZING
, 0, 10, 20,FALSE
,FALSE
},
332 static UINT_PTR WINAPI
resize_template_hook(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
334 static RECT initrc
, rc
;
335 static int index
, count
;
336 static BOOL gotSWP_bottom
, gotShowWindow
;
337 HWND parent
= GetParent( dlg
);
339 #define MAXNRCTRLS 30
340 static RECT ctrlrcs
[MAXNRCTRLS
];
341 static int ctrlids
[MAXNRCTRLS
];
342 static HWND ctrls
[MAXNRCTRLS
];
351 index
= ((OPENFILENAMEA
*)lParam
)->lCustData
;
353 gotSWP_bottom
= gotShowWindow
= FALSE
;
355 style
= GetWindowLongA( parent
, GWL_STYLE
);
356 if( resize_testcases
[index
].flags
& OFN_ENABLESIZING
)
357 if( !(style
& WS_SIZEBOX
)) {
358 win_skip( "OFN_ENABLESIZING flag not supported.\n");
359 resizesupported
= FALSE
;
360 PostMessageA( parent
, WM_COMMAND
, IDCANCEL
, 0);
362 ok( style
& WS_SIZEBOX
,
363 "testid %d: dialog should have a WS_SIZEBOX style.\n", index
);
365 ok( !(style
& WS_SIZEBOX
),
366 "testid %d: dialog should not have a WS_SIZEBOX style.\n", index
);
371 if(( (LPNMHDR
)lParam
)->code
== CDN_FOLDERCHANGE
){
372 GetWindowRect( parent
, &initrc
);
373 if( (resize
= resize_testcases
[index
].resize_folderchange
)){
374 MoveWindow( parent
, initrc
.left
,initrc
.top
, initrc
.right
- initrc
.left
+ resize
,
375 initrc
.bottom
- initrc
.top
+ resize
, TRUE
);
377 SetTimer( dlg
, 0, 100, 0);
384 /* store the control rectangles */
385 if( resize_testcases
[index
].testcontrols
) {
388 for( i
= 0, ctrl
= GetWindow( parent
, GW_CHILD
);
389 i
< MAXNRCTRLS
&& ctrl
;
390 i
++, ctrl
= GetWindow( ctrl
, GW_HWNDNEXT
)) {
391 ctrlids
[i
] = GetDlgCtrlID( ctrl
);
392 GetWindowRect( ctrl
, &ctrlrcs
[i
]);
393 MapWindowPoints( NULL
, parent
, (LPPOINT
) &ctrlrcs
[i
], 2);
398 if( (resize
= resize_testcases
[index
].resize_timer1
)){
399 GetWindowRect( parent
, &rc
);
400 MoveWindow( parent
, rc
.left
,rc
.top
, rc
.right
- rc
.left
+ resize
,
401 rc
.bottom
- rc
.top
+ resize
, TRUE
);
403 } else if( count
== 1){
404 resize
= resize_testcases
[index
].resize_check
;
405 GetWindowRect( parent
, &rc
);
406 todo_wine_if( resize_testcases
[index
].todo
){
407 ok( resize
== rc
.right
- rc
.left
- initrc
.right
+ initrc
.left
,
408 "testid %d size-x change %d expected %d\n", index
,
409 rc
.right
- rc
.left
- initrc
.right
+ initrc
.left
, resize
);
410 ok( resize
== rc
.bottom
- rc
.top
- initrc
.bottom
+ initrc
.top
,
411 "testid %d size-y change %d expected %d\n", index
,
412 rc
.bottom
- rc
.top
- initrc
.bottom
+ initrc
.top
, resize
);
414 if( resize_testcases
[index
].testcontrols
) {
417 for( i
= 0; i
< nrctrls
; i
++) {
418 GetWindowRect( ctrls
[i
], &rc
);
419 MapWindowPoints( NULL
, parent
, (LPPOINT
) &rc
, 2);
422 /* test if RECT R1, moved and sized result in R2 */
423 #define TESTRECTS( R1, R2, Mx, My, Sx, Sy) \
424 ((R1).left + (Mx) ==(R2).left \
425 &&(R1).top + (My) ==(R2).top \
426 &&(R1).right + (Mx) + (Sx) == (R2).right \
427 &&(R1).bottom + (My) + (Sy) ==(R2).bottom)
429 /* sized horizontal and moved vertical */
432 ok( TESTRECTS( ctrlrcs
[i
], rc
, 0, 10, 10, 0),
433 "control id %03x should have sized horizontally and moved vertically, before %s after %s\n",
434 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
435 wine_dbgstr_rect( &rc
));
437 /* sized horizontal and vertical */
439 ok( TESTRECTS( ctrlrcs
[i
], rc
, 0, 0, 10, 10),
440 "control id %03x should have sized horizontally and vertically, before %s after %s\n",
441 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
442 wine_dbgstr_rect( &rc
));
444 /* moved horizontal and vertical */
447 ok( TESTRECTS( ctrlrcs
[i
], rc
, 10, 10, 0, 0),
448 "control id %03x should have moved horizontally and vertically, before %s after %s\n",
449 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
450 wine_dbgstr_rect( &rc
));
452 /* moved vertically */
456 ok( TESTRECTS( ctrlrcs
[i
], rc
, 0, 10, 0, 0),
457 "control id %03x should have moved vertically, before %s after %s\n",
458 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
459 wine_dbgstr_rect( &rc
));
461 /* resized horizontal */
462 case cmb2
: /* aka IDC_LOOKIN */
463 ok( TESTRECTS( ctrlrcs
[i
], rc
, 0, 0, 10, 0)||
464 TESTRECTS( ctrlrcs
[i
], rc
, 0, 0, 0, 0), /* Vista and higher */
465 "control id %03x should have resized horizontally, before %s after %s\n",
466 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
467 wine_dbgstr_rect( &rc
));
469 /* non moving non sizing controls */
471 ok( TESTRECTS( rc
, ctrlrcs
[i
], 0, 0, 0, 0),
472 "control id %03x was moved/resized, before %s after %s\n",
473 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
474 wine_dbgstr_rect( &rc
));
476 /* todo_wine: non moving non sizing controls */
479 ok( TESTRECTS( rc
, ctrlrcs
[i
], 0, 0, 0, 0),
480 "control id %03x was moved/resized, before %s after %s\n",
481 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
482 wine_dbgstr_rect( &rc
));
484 /* don't test: id is not unique */
491 trace("untested control id %03x before %s after %s\n",
492 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
493 wine_dbgstr_rect( &rc
));
500 PostMessageA( parent
, WM_COMMAND
, IDCANCEL
, 0);
505 case WM_WINDOWPOSCHANGING
:
507 WINDOWPOS
*pwp
= (WINDOWPOS
*)lParam
;
508 if( !index
&& pwp
->hwndInsertAfter
== HWND_BOTTOM
){
509 gotSWP_bottom
= TRUE
;
510 ok(!gotShowWindow
, "The WM_WINDOWPOSCHANGING message came after a WM_SHOWWINDOW message\n");
517 gotShowWindow
= TRUE
;
518 ok(gotSWP_bottom
, "No WM_WINDOWPOSCHANGING message came before a WM_SHOWWINDOW message\n");
526 static void test_resize(void)
528 OPENFILENAMEA ofn
= { OPENFILENAME_SIZE_VERSION_400A
};
529 char filename
[1024] = {0};
533 ofn
.lpstrFile
= filename
;
535 ofn
.lpfnHook
= resize_template_hook
;
536 ofn
.hInstance
= GetModuleHandleA(NULL
);
537 ofn
.lpTemplateName
= "template_sz";
538 for( i
= 0; resize_testcases
[i
].flags
!= 0xffffffff; i
++) {
540 ofn
.Flags
= resize_testcases
[i
].flags
|
541 OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
| OFN_SHOWHELP
;
542 ret
= GetOpenFileNameA(&ofn
);
543 ok(!ret
, "GetOpenFileName returned %#x\n", ret
);
544 ret
= CommDlgExtendedError();
545 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
549 /* test cases for control message IDOK */
550 /* Show case for bug #19079 */
552 int retval
; /* return code of the message handler */
553 BOOL setmsgresult
; /* set the result in the DWLP_MSGRESULT */
554 BOOL usemsgokstr
; /* use the FILEOKSTRING message instead of WM_NOTIFY:CDN_FILEOK */
555 BOOL do_subclass
; /* subclass the dialog hook procedure */
556 BOOL expclose
; /* is the dialog expected to close ? */
557 BOOL actclose
; /* has the dialog actually closed ? */
558 } ok_wndproc_testcase
;
560 static ok_wndproc_testcase ok_testcases
[] = {
561 { 0, FALSE
, FALSE
, FALSE
, TRUE
},
562 { 0, TRUE
, FALSE
, FALSE
, TRUE
},
563 { 0, FALSE
, FALSE
, TRUE
, TRUE
},
564 { 0, TRUE
, FALSE
, TRUE
, TRUE
},
565 { 1, FALSE
, FALSE
, FALSE
, TRUE
},
566 { 1, TRUE
, FALSE
, FALSE
, FALSE
},
567 { 1, FALSE
, FALSE
, TRUE
, FALSE
},
568 { 1, TRUE
, FALSE
, TRUE
, FALSE
},
569 /* FILEOKSTRING tests */
570 { 1, TRUE
, TRUE
, FALSE
, FALSE
},
571 { 1, FALSE
, TRUE
, TRUE
, FALSE
},
576 /* test_ok_wndproc can be used as hook procedure or a subclass
577 * window proc for the file dialog */
578 static UINT_PTR WINAPI
test_ok_wndproc(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
580 HWND parent
= GetParent( dlg
);
581 static ok_wndproc_testcase
*testcase
= NULL
;
582 static UINT msgFILEOKSTRING
;
583 if (msg
== WM_INITDIALOG
)
585 testcase
= (ok_wndproc_testcase
*)((OPENFILENAMEA
*)lParam
)->lCustData
;
586 testcase
->actclose
= TRUE
;
587 msgFILEOKSTRING
= RegisterWindowMessageA( FILEOKSTRINGA
);
589 if( msg
== WM_NOTIFY
) {
590 if(((LPNMHDR
)lParam
)->code
== CDN_FOLDERCHANGE
) {
591 SetTimer( dlg
, 0, 100, 0);
592 PostMessageA( parent
, WM_COMMAND
, IDOK
, 0);
594 } else if(((LPNMHDR
)lParam
)->code
== CDN_FILEOK
) {
595 if( testcase
->usemsgokstr
)
597 if( testcase
->setmsgresult
)
598 SetWindowLongPtrA( dlg
, DWLP_MSGRESULT
, testcase
->retval
);
599 return testcase
->retval
;
602 if( msg
== msgFILEOKSTRING
) {
603 if( !testcase
->usemsgokstr
)
605 if( testcase
->setmsgresult
)
606 SetWindowLongPtrA( dlg
, DWLP_MSGRESULT
, testcase
->retval
);
607 return testcase
->retval
;
609 if( msg
== WM_TIMER
) {
610 /* the dialog did not close automatically */
611 testcase
->actclose
= FALSE
;
613 PostMessageA( parent
, WM_COMMAND
, IDCANCEL
, 0);
616 if( testcase
&& testcase
->do_subclass
)
617 return DefWindowProcA( dlg
, msg
, wParam
, lParam
);
621 static UINT_PTR WINAPI
ok_template_hook(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
623 if (msg
== WM_SETFONT
)
624 SetWindowLongPtrA( dlg
, GWLP_WNDPROC
, (LONG_PTR
) test_ok_wndproc
);
628 static void test_ok(void)
630 OPENFILENAMEA ofn
= { OPENFILENAME_SIZE_VERSION_400A
};
631 char filename
[1024] = {0};
632 char tmpfilename
[ MAX_PATH
];
633 char curdir
[MAX_PATH
];
638 cdret
= GetCurrentDirectoryA(sizeof(curdir
), curdir
);
639 ok(cdret
, "Failed to get current dir err %d\n", GetLastError());
640 if (!GetTempFileNameA(".", "txt", 0, tmpfilename
)) {
641 skip("Failed to create a temporary file name\n");
644 ofn
.lpstrFile
= filename
;
646 ofn
.hInstance
= GetModuleHandleA(NULL
);
647 ofn
.lpTemplateName
= "template1";
648 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
;
649 for( i
= 0; ok_testcases
[i
].retval
!= -1; i
++) {
650 strcpy( filename
, tmpfilename
);
651 ofn
.lCustData
= (LPARAM
)(ok_testcases
+ i
);
652 ofn
.lpfnHook
= ok_testcases
[i
].do_subclass
? ok_template_hook
: test_ok_wndproc
;
653 ret
= GetOpenFileNameA(&ofn
);
654 ok( ok_testcases
[i
].expclose
== ok_testcases
[i
].actclose
,
655 "testid %d: Open File dialog should %shave closed.\n", i
,
656 ok_testcases
[i
].expclose
? "" : "NOT ");
657 ok(ret
== ok_testcases
[i
].expclose
, "testid %d: GetOpenFileName returned %#x\n", i
, ret
);
658 ret
= CommDlgExtendedError();
659 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
660 cdret
= SetCurrentDirectoryA(curdir
);
661 ok(cdret
, "Failed to restore current dir err %d\n", GetLastError());
663 ret
= DeleteFileA( tmpfilename
);
664 ok( ret
, "Failed to delete temporary file %s err %d\n", tmpfilename
, GetLastError());
667 /* test arranging with a custom template */
669 int x
, y
; /* left, top coordinates */
670 int cx
, cy
; /* width and height */
673 int nrcontrols
; /* 0: no controls, 1: just the stc32 control 2: with button */
678 } arrange_tests
[] = {
679 /* do not change the first two cases: used to get the uncustomized sizes */
680 { 0, {0},{0},{0},0 },
681 { 0, {0},{0},{0}, OFN_SHOWHELP
},
682 /* two tests with just a subdialog, no controls */
683 { 0, {0, 0, 316, 76},{0},{0},0 },
684 { 0, {0, 0, 100, 76},{0},{0}, OFN_SHOWHELP
},
685 /* now with a control with id stc32 */
686 { 1, {0, 0, 316, 76} ,{0, 0, 204, 76,},{0},0 }, /* bug #17748*/
687 { 1, {0, 0, 316, 76} ,{0, 0, 204, 76,},{0}, OFN_SHOWHELP
}, /* bug #17748*/
688 /* tests with size of the stc32 control higher or wider then the standard dialog */
689 { 1, {0, 0, 316, 170} ,{0, 0, 204, 170,},{0},0 },
690 { 1, {0, 0, 316, 165} ,{0, 0, 411, 165,},{0}, OFN_SHOWHELP
},
691 /* move the stc32 control around */
692 { 1, {0, 0, 300, 100} ,{73, 17, 50, 50,},{0},0 },
694 { 2, {0, 0, 280, 100} ,{0, 0, 50, 50,},{300,20,30,30},0 },
695 /* enable resizing should make the dialog bigger */
696 { 0, {0},{0},{0}, OFN_SHOWHELP
|OFN_ENABLESIZING
},
701 static UINT_PTR WINAPI
template_hook_arrange(HWND dlgChild
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
703 static int index
, fixhelp
;
704 static posz posz0
[2];
705 static RECT clrcParent
, clrcChild
, rcStc32
;
706 static HWND hwndStc32
;
709 dlgParent
= GetParent( dlgChild
);
710 if (msg
== WM_INITDIALOG
) {
711 index
= ((OPENFILENAMEA
*)lParam
)->lCustData
;
712 /* get the positions before rearrangement */
713 GetClientRect( dlgParent
, &clrcParent
);
714 GetClientRect( dlgChild
, &clrcChild
);
715 hwndStc32
= GetDlgItem( dlgChild
, stc32
);
716 if( hwndStc32
) GetWindowRect( hwndStc32
, &rcStc32
);
718 if (msg
== WM_NOTIFY
&& ((LPNMHDR
)lParam
)->code
== CDN_FOLDERCHANGE
) {
721 GetWindowRect( dlgParent
, &wrcParent
);
722 /* the fist two "tests" just save the dialogs position, with and without
725 posz0
[0].x
= wrcParent
.left
;
726 posz0
[0].y
= wrcParent
.top
;
727 posz0
[0].cx
= wrcParent
.right
- wrcParent
.left
;
728 posz0
[0].cy
= wrcParent
.bottom
- wrcParent
.top
;
729 } else if( index
== 1) {
730 posz0
[1].x
= wrcParent
.left
;
731 posz0
[1].y
= wrcParent
.top
;
732 posz0
[1].cx
= wrcParent
.right
- wrcParent
.left
;
733 posz0
[1].cy
= wrcParent
.bottom
- wrcParent
.top
;
734 fixhelp
= posz0
[1].cy
- posz0
[0].cy
;
738 int expectx
, expecty
;
741 withhelp
= (arrange_tests
[index
].ofnflags
& OFN_SHOWHELP
) != 0;
742 GetWindowRect( dlgParent
, &wrcParent
);
744 /* case with no custom subitem with stc32:
745 * default to all custom controls below the standard */
746 expecty
= posz0
[withhelp
].cy
+ clrcChild
.bottom
;
747 expectx
= posz0
[withhelp
].cx
;
749 /* special case: there is a control with id stc32 */
750 /* expected height */
751 expecty
= posz0
[withhelp
].cy
;
752 if( rcStc32
.bottom
- rcStc32
.top
+ (withhelp
? 0 : fixhelp
) > clrcParent
.bottom
) {
753 expecty
+= clrcChild
.bottom
- clrcParent
.bottom
;
754 if( !withhelp
) expecty
+= fixhelp
;
757 expecty
+= clrcChild
.bottom
- ( rcStc32
.bottom
- rcStc32
.top
) ;
759 expectx
= posz0
[withhelp
].cx
;
760 if( rcStc32
.right
- rcStc32
.left
> clrcParent
.right
) {
761 expectx
+= clrcChild
.right
- clrcParent
.right
;
764 expectx
+= clrcChild
.right
- ( rcStc32
.right
- rcStc32
.left
) ;
766 style
= GetWindowLongA( dlgParent
, GWL_STYLE
);
767 if( !(style
& WS_SIZEBOX
)) {
768 /* without the OFN_ENABLESIZING flag */
769 ok( wrcParent
.bottom
- wrcParent
.top
== expecty
,
770 "Wrong height of dialog %d, expected %d\n",
771 wrcParent
.bottom
- wrcParent
.top
, expecty
);
772 ok( wrcParent
.right
- wrcParent
.left
== expectx
,
773 "Wrong width of dialog %d, expected %d\n",
774 wrcParent
.right
- wrcParent
.left
, expectx
);
776 /* with the OFN_ENABLESIZING flag */
777 ok( wrcParent
.bottom
- wrcParent
.top
> expecty
,
778 "Wrong height of dialog %d, expected more than %d\n",
779 wrcParent
.bottom
- wrcParent
.top
, expecty
);
780 ok( wrcParent
.right
- wrcParent
.left
> expectx
,
781 "Wrong width of dialog %d, expected more than %d\n",
782 wrcParent
.right
- wrcParent
.left
, expectx
);
786 PostMessageA( dlgParent
, WM_COMMAND
, IDCANCEL
, 0);
791 static void test_arrange(void)
793 OPENFILENAMEA ofn
= {0};
794 char filename
[1024] = {0};
799 DLGTEMPLATE
*template;
800 DLGITEMTEMPLATE
*itemtemplateStc32
, *itemtemplateBtn
;
803 /* load subdialog template into memory */
804 hRes
= FindResourceA( GetModuleHandleA(NULL
), "template_stc32", (LPSTR
)RT_DIALOG
);
805 hDlgTmpl
= LoadResource( GetModuleHandleA(NULL
), hRes
);
806 /* get pointers to the structures for the dialog and the controls */
807 pv
= LockResource( hDlgTmpl
);
808 template = (DLGTEMPLATE
*)pv
;
809 if( template->x
!= 11111) {
810 win_skip("could not find the dialog template\n");
813 /* skip dialog template, menu, class and title */
814 pv
+= sizeof(DLGTEMPLATE
);
815 pv
+= 3 * sizeof(WORD
);
820 /* align on 32 bit boundaries */
821 pv
= (LPBYTE
)(((UINT_PTR
)pv
+ 3 ) & ~3);
822 itemtemplateStc32
= (DLGITEMTEMPLATE
*)pv
;
823 if( itemtemplateStc32
->x
!= 22222) {
824 win_skip("could not find the first item template\n");
827 /* skip itemtemplate, class, title and creation data */
828 pv
+= sizeof(DLGITEMTEMPLATE
);
829 pv
+= 4 * sizeof(WORD
);
830 /* align on 32 bit boundaries */
831 pv
= (LPBYTE
)(((UINT_PTR
)pv
+ 3 ) & ~3);
832 itemtemplateBtn
= (DLGITEMTEMPLATE
*)pv
;
833 if( itemtemplateBtn
->x
!= 12345) {
834 win_skip("could not find the second item template\n");
838 ofn
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
839 ofn
.lpstrFile
= filename
;
841 ofn
.lpfnHook
= template_hook_arrange
;
842 ofn
.hInstance
= hDlgTmpl
;
843 ofn
.lpstrFilter
="text\0*.txt\0All\0*\0\0";
844 for( i
= 0; arrange_tests
[i
].nrcontrols
!= -1; i
++) {
846 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATEHANDLE
| OFN_HIDEREADONLY
|
847 arrange_tests
[i
].ofnflags
;
848 template->cdit
= arrange_tests
[i
].nrcontrols
;
849 template->x
= arrange_tests
[i
].poszDlg
.x
;
850 template->y
= arrange_tests
[i
].poszDlg
.y
;
851 template->cx
= arrange_tests
[i
].poszDlg
.cx
;
852 template->cy
= arrange_tests
[i
].poszDlg
.cy
;
853 itemtemplateStc32
->x
= arrange_tests
[i
].poszStc32
.x
;
854 itemtemplateStc32
->y
= arrange_tests
[i
].poszStc32
.y
;
855 itemtemplateStc32
->cx
= arrange_tests
[i
].poszStc32
.cx
;
856 itemtemplateStc32
->cy
= arrange_tests
[i
].poszStc32
.cy
;
857 itemtemplateBtn
->x
= arrange_tests
[i
].poszBtn
.x
;
858 itemtemplateBtn
->y
= arrange_tests
[i
].poszBtn
.y
;
859 itemtemplateBtn
->cx
= arrange_tests
[i
].poszBtn
.cx
;
860 itemtemplateBtn
->cy
= arrange_tests
[i
].poszBtn
.cy
;
861 ret
= GetOpenFileNameA(&ofn
);
862 ok(!ret
, "GetOpenFileNameA returned %#x\n", ret
);
863 ret
= CommDlgExtendedError();
864 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
868 static CHAR SYSDIR
[MAX_PATH
];
870 static UINT_PTR CALLBACK
path_hook_proc( HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
874 if( msg
== WM_NOTIFY
)
876 nmh
= (LPNMHDR
) lParam
;
877 if( nmh
->code
== CDN_INITDONE
)
879 PostMessageA( GetParent(hDlg
), WM_COMMAND
, IDCANCEL
, FALSE
);
881 else if ( nmh
->code
== CDN_FOLDERCHANGE
)
886 memset(buf
, 0x66, sizeof(buf
));
887 ret
= SendMessageA( GetParent(hDlg
), CDM_GETFOLDERPATH
, sizeof(buf
), (LPARAM
)buf
);
888 ok(!lstrcmpiA(SYSDIR
, buf
), "Expected '%s', got '%s'\n", SYSDIR
, buf
);
889 ok(lstrlenA(SYSDIR
) + 1 == ret
, "Expected %d, got %d\n", lstrlenA(SYSDIR
) + 1, ret
);
896 static void test_getfolderpath(void)
900 char szFileName
[MAX_PATH
] = "";
901 char szInitialDir
[MAX_PATH
];
903 /* We need to pick a different directory as the other tests because of new
904 * Windows 7 behavior.
906 GetSystemDirectoryA(szInitialDir
, MAX_PATH
);
907 lstrcpyA(SYSDIR
, szInitialDir
);
909 ZeroMemory(&ofn
, sizeof(ofn
));
911 ofn
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
912 ofn
.hwndOwner
= NULL
;
913 ofn
.lpstrFilter
= "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
914 ofn
.lpstrFile
= szFileName
;
915 ofn
.nMaxFile
= MAX_PATH
;
916 ofn
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_ENABLEHOOK
;
917 ofn
.lpstrDefExt
= "txt";
918 ofn
.lpfnHook
= path_hook_proc
;
919 ofn
.lpstrInitialDir
= szInitialDir
;
921 result
= GetOpenFileNameA(&ofn
);
922 ok(FALSE
== result
, "expected FALSE, got %d\n", result
);
923 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
924 CommDlgExtendedError());
926 result
= GetSaveFileNameA(&ofn
);
927 ok(FALSE
== result
, "expected FALSE, got %d\n", result
);
928 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
929 CommDlgExtendedError());
932 static void test_resizable2(void)
934 OPENFILENAMEA ofn
= {0};
935 char filename
[1024] = "pls press Enter if sizable, Esc otherwise";
938 /* interactive because there is no hook function */
939 if( !winetest_interactive
) {
940 skip( "some interactive resizable dialog tests (set WINETEST_INTERACTIVE=1)\n");
943 ofn
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
944 ofn
.lpstrFile
= filename
;
947 ofn
.hInstance
= GetModuleHandleA(NULL
);
948 ofn
.lpTemplateName
= "template1";
949 ofn
.Flags
= OFN_EXPLORER
;
950 #define ISSIZABLE TRUE
951 ret
= GetOpenFileNameA(&ofn
);
952 ok( ret
== ISSIZABLE
, "File Dialog should have been sizable\n");
953 ret
= CommDlgExtendedError();
954 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
955 ofn
.Flags
= OFN_EXPLORER
| OFN_ENABLETEMPLATE
;
956 ret
= GetOpenFileNameA(&ofn
);
957 ok( ret
!= ISSIZABLE
, "File Dialog should NOT have been sizable\n");
958 ret
= CommDlgExtendedError();
959 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
960 ofn
.Flags
= OFN_EXPLORER
| OFN_ENABLETEMPLATEHANDLE
;
961 ofn
.hInstance
= LoadResource( GetModuleHandleA(NULL
), FindResourceA( GetModuleHandleA(NULL
), "template1", (LPSTR
)RT_DIALOG
));
962 ofn
.lpTemplateName
= NULL
;
963 ret
= GetOpenFileNameA(&ofn
);
964 ok( ret
!= ISSIZABLE
, "File Dialog should NOT have been sizable\n");
965 ret
= CommDlgExtendedError();
966 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
967 ofn
.Flags
= OFN_EXPLORER
| OFN_ENABLEHOOK
;
968 ret
= GetOpenFileNameA(&ofn
);
969 ok( ret
!= ISSIZABLE
, "File Dialog should NOT have been sizable\n");
970 ret
= CommDlgExtendedError();
971 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
975 static void test_mru(void)
977 ok_wndproc_testcase testcase
= {0};
978 OPENFILENAMEA ofn
= { OPENFILENAME_SIZE_VERSION_400A
};
979 const char *test_dir_name
= "C:\\mru_test";
980 const char *test_file_name
= "test.txt";
981 const char *test_full_path
= "C:\\mru_test\\test.txt";
982 char filename_buf
[MAX_PATH
];
985 ofn
.lpstrFile
= filename_buf
;
986 ofn
.nMaxFile
= sizeof(filename_buf
);
987 ofn
.lpTemplateName
= "template1";
988 ofn
.hInstance
= GetModuleHandleA(NULL
);
989 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
| OFN_NOCHANGEDIR
;
990 ofn
.lCustData
= (LPARAM
)&testcase
;
991 ofn
.lpfnHook
= test_ok_wndproc
;
993 SetLastError(0xdeadbeef);
994 ret
= CreateDirectoryA(test_dir_name
, NULL
);
995 ok(ret
== TRUE
, "CreateDirectoryA should have succeeded: %d\n", GetLastError());
997 /* "teach" comdlg32 about this directory */
998 strcpy(filename_buf
, test_full_path
);
999 SetLastError(0xdeadbeef);
1000 ret
= GetOpenFileNameA(&ofn
);
1001 ok(ret
, "GetOpenFileNameA should have succeeded: %d\n", GetLastError());
1002 ret
= CommDlgExtendedError();
1003 ok(!ret
, "CommDlgExtendedError returned %x\n", ret
);
1004 ok(testcase
.actclose
, "Open File dialog should have closed.\n");
1005 ok(!strcmp(ofn
.lpstrFile
, test_full_path
), "Expected to get %s, got %s\n", test_full_path
, ofn
.lpstrFile
);
1007 /* get a filename without a full path. it should return the file in
1008 * test_dir_name, not in the CWD */
1009 strcpy(filename_buf
, test_file_name
);
1010 SetLastError(0xdeadbeef);
1011 ret
= GetOpenFileNameA(&ofn
);
1012 ok(ret
, "GetOpenFileNameA should have succeeded: %d\n", GetLastError());
1013 ret
= CommDlgExtendedError();
1014 ok(!ret
, "CommDlgExtendedError returned %x\n", ret
);
1015 ok(testcase
.actclose
, "Open File dialog should have closed.\n");
1016 if(strcmp(ofn
.lpstrFile
, test_full_path
) != 0)
1017 win_skip("Platform doesn't save MRU data\n");
1019 SetLastError(0xdeadbeef);
1020 ret
= RemoveDirectoryA(test_dir_name
);
1021 ok(ret
== TRUE
, "RemoveDirectoryA should have succeeded: %d\n", GetLastError());
1024 static UINT_PTR WINAPI
test_extension_wndproc(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1026 HWND parent
= GetParent( dlg
);
1027 if( msg
== WM_NOTIFY
) {
1028 SetTimer( dlg
, 0, 1000, 0);
1029 PostMessageA( parent
, WM_COMMAND
, IDOK
, 0);
1031 if( msg
== WM_TIMER
) {
1032 /* the dialog did not close automatically */
1034 PostMessageA( parent
, WM_COMMAND
, IDCANCEL
, 0);
1039 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
1041 static void test_extension_helper(OPENFILENAMEA
* ofn
, const char *filter
,
1042 const char *expected_filename
)
1048 strcpy(ofn
->lpstrFile
, "deadbeef");
1049 ofn
->lpstrFilter
= filter
;
1051 boolret
= GetSaveFileNameA(ofn
);
1052 ok(boolret
, "%s: expected TRUE\n", filter
);
1054 ret
= CommDlgExtendedError();
1055 ok(!ret
, "%s: CommDlgExtendedError returned %#x\n", filter
, ret
);
1057 filename_ptr
= ofn
->lpstrFile
+ ofn
->nFileOffset
;
1058 ok(strcmp(filename_ptr
, expected_filename
) == 0,
1059 "%s: Filename is %s, expected %s\n", filter
, filename_ptr
, expected_filename
);
1062 static void test_extension(void)
1064 OPENFILENAMEA ofn
= { OPENFILENAME_SIZE_VERSION_400A
};
1065 char filename
[1024] = {0};
1066 char curdir
[MAX_PATH
];
1070 const char *defext_concrete_filters
[] = {
1071 "TestFilter (*.abc)\0*.abc\0",
1072 "TestFilter (*.abc;)\0*.abc;\0",
1073 "TestFilter (*.abc;*.def)\0*.abc;*.def\0",
1076 const char *defext_wildcard_filters
[] = {
1077 "TestFilter (*.pt*)\0*.pt*\0",
1078 "TestFilter (*.pt*;*.abc)\0*.pt*;*.abc\0",
1079 "TestFilter (*.ab?)\0*.ab?\0",
1080 "TestFilter (*.*)\0*.*\0",
1081 "TestFilter (*sav)\0*sav\0",
1082 NULL
/* is a test, not an endmark! */
1085 boolret
= GetCurrentDirectoryA(sizeof(curdir
), curdir
);
1086 ok(boolret
, "Failed to get current dir err %d\n", GetLastError());
1088 ofn
.hwndOwner
= NULL
;
1089 ofn
.lpstrFile
= filename
;
1090 ofn
.nMaxFile
= MAX_PATH
;
1091 ofn
.Flags
= OFN_EXPLORER
| OFN_ENABLEHOOK
;
1092 ofn
.lpstrInitialDir
= curdir
;
1093 ofn
.lpfnHook
= test_extension_wndproc
;
1094 ofn
.nFileExtension
= 0;
1096 ofn
.lpstrDefExt
= NULL
;
1098 /* Without lpstrDefExt, append no extension */
1099 test_extension_helper(&ofn
, "TestFilter (*.abc) lpstrDefExt=NULL\0*.abc\0", "deadbeef");
1100 test_extension_helper(&ofn
, "TestFilter (*.ab?) lpstrDefExt=NULL\0*.ab?\0", "deadbeef");
1102 ofn
.lpstrDefExt
= "";
1104 /* If lpstrDefExt="" and the filter has a concrete extension, append it */
1105 test_extension_helper(&ofn
, "TestFilter (*.abc) lpstrDefExt=\"\"\0*.abc\0", "deadbeef.abc");
1107 /* If lpstrDefExt="" and the filter has a wildcard extension, do nothing */
1108 test_extension_helper(&ofn
, "TestFilter (*.ab?) lpstrDefExt=\"\"\0*.ab?\0", "deadbeef");
1110 ofn
.lpstrDefExt
= "xyz";
1112 /* Append concrete extensions from filters */
1113 for (i
= 0; i
< ARRAY_SIZE(defext_concrete_filters
); i
++) {
1114 test_extension_helper(&ofn
, defext_concrete_filters
[i
], "deadbeef.abc");
1117 /* Append nothing from this filter */
1118 test_extension_helper(&ofn
, "TestFilter (*.)\0*.\0", "deadbeef");
1120 /* Ignore wildcard extensions in filters */
1121 for (i
= 0; i
< ARRAY_SIZE(defext_wildcard_filters
); i
++) {
1122 test_extension_helper(&ofn
, defext_wildcard_filters
[i
], "deadbeef.xyz");
1125 /* Append valid extensions consisting of multiple parts */
1126 test_extension_helper(&ofn
, "TestFilter (*.abc.def)\0*.abc.def\0", "deadbeef.abc.def");
1127 test_extension_helper(&ofn
, "TestFilter (.abc.def)\0.abc.def\0", "deadbeef.abc.def");
1128 test_extension_helper(&ofn
, "TestFilter (*.*.def)\0*.*.def\0", "deadbeef.xyz");
1134 static BOOL WINAPI
test_null_enum(HWND hwnd
, LPARAM lParam
)
1136 /* Find the textbox and send a filename so IDOK will work.
1137 If the file textbox is empty IDOK will be ignored */
1139 if(GetClassNameA(hwnd
, className
, sizeof(className
)) > 0 && !strcmp("Edit",className
))
1141 SetWindowTextA(hwnd
, "testfile");
1142 return FALSE
; /* break window enumeration */
1147 static UINT_PTR WINAPI
test_null_wndproc(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1149 HWND parent
= GetParent( dlg
);
1150 if( msg
== WM_NOTIFY
) {
1151 SetTimer( dlg
, 0, 100, 0);
1152 SetTimer( dlg
, 1, 1000, 0);
1153 EnumChildWindows( parent
, test_null_enum
, 0);
1155 if( msg
== WM_TIMER
) {
1157 PostMessageA( parent
, WM_COMMAND
, IDOK
, 0);
1159 /* the dialog did not close automatically */
1161 PostMessageA( parent
, WM_COMMAND
, IDCANCEL
, 0);
1167 static void test_null_filename(void)
1169 OPENFILENAMEA ofnA
= {0};
1170 OPENFILENAMEW ofnW
= {0};
1171 WCHAR filterW
[] = {'t','e','x','t','\0','*','.','t','x','t','\0',
1172 'A','l','l','\0','*','\0','\0'};
1175 ofnA
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
1176 ofnA
.lpstrFile
= NULL
;
1178 ofnA
.nFileOffset
= 0xdead;
1179 ofnA
.nFileExtension
= 0xbeef;
1180 ofnA
.lpfnHook
= test_null_wndproc
;
1181 ofnA
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
;
1182 ofnA
.hInstance
= GetModuleHandleA(NULL
);
1183 ofnA
.lpstrFilter
= "text\0*.txt\0All\0*\0\0";
1184 ofnA
.lpstrDefExt
= NULL
;
1185 ret
= GetOpenFileNameA(&ofnA
);
1186 todo_wine
ok(ret
, "GetOpenFileNameA returned %#x\n", ret
);
1187 ret
= CommDlgExtendedError();
1188 todo_wine
ok(!ret
, "CommDlgExtendedError returned %#x, should be 0\n", ret
);
1190 todo_wine
ok(ofnA
.nFileOffset
!= 0xdead, "ofnA.nFileOffset is 0xdead\n");
1191 todo_wine
ok(ofnA
.nFileExtension
!= 0xbeef, "ofnA.nFileExtension is 0xbeef\n");
1193 ofnA
.lpstrFile
= NULL
;
1194 ofnA
.nMaxFile
= 1024; /* bogus input - lpstrFile = NULL but fake 1024 bytes available */
1195 ofnA
.nFileOffset
= 0xdead;
1196 ofnA
.nFileExtension
= 0xbeef;
1197 ret
= GetOpenFileNameA(&ofnA
);
1198 ok(ret
, "GetOpenFileNameA returned %#x\n", ret
);
1199 ret
= CommDlgExtendedError();
1200 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
1202 ok(ofnA
.nFileOffset
!= 0xdead, "ofnA.nFileOffset is 0xdead\n");
1203 ok(ofnA
.nFileExtension
== 0, "ofnA.nFileExtension is 0x%x, should be 0\n", ofnA
.nFileExtension
);
1206 ofnW
.lStructSize
= OPENFILENAME_SIZE_VERSION_400W
;
1207 ofnW
.lpstrFile
= NULL
;
1209 ofnW
.nFileOffset
= 0xdead;
1210 ofnW
.nFileExtension
= 0xbeef;
1211 ofnW
.lpfnHook
= test_null_wndproc
;
1212 ofnW
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
;
1213 ofnW
.hInstance
= GetModuleHandleW(NULL
);
1214 ofnW
.lpstrFilter
= filterW
;
1215 ofnW
.lpstrDefExt
= NULL
;
1216 ret
= GetOpenFileNameW(&ofnW
);
1217 todo_wine
ok(ret
, "GetOpenFileNameW returned %#x\n", ret
);
1218 ret
= CommDlgExtendedError();
1219 todo_wine
ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
1221 todo_wine
ok(ofnW
.nFileOffset
!= 0xdead, "ofnW.nFileOffset is 0xdead\n");
1222 todo_wine
ok(ofnW
.nFileExtension
!= 0xbeef, "ofnW.nFileExtension is 0xbeef\n");
1224 ofnW
.lpstrFile
= NULL
;
1225 ofnW
.nMaxFile
= 1024; /* bogus input - lpstrFile = NULL but fake 1024 bytes available */
1226 ofnW
.nFileOffset
= 0xdead;
1227 ofnW
.nFileExtension
= 0xbeef;
1228 ret
= GetOpenFileNameW(&ofnW
);
1229 ok(ret
, "GetOpenFileNameA returned %#x\n", ret
);
1230 ret
= CommDlgExtendedError();
1231 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
1233 ok(ofnW
.nFileOffset
!= 0xdead, "ofnW.nFileOffset is 0xdead\n");
1234 ok(ofnW
.nFileExtension
== 0, "ofnW.nFileExtension is 0x%x, should be 0\n", ofnW
.nFileExtension
);
1239 test_DialogCancel();
1240 test_create_view_window2();
1241 test_create_view_template();
1245 test_getfolderpath();
1247 if( resizesupported
) test_resizable2();
1249 test_null_filename();