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
23 #include <wine/test.h>
34 static BOOL resizesupported
= TRUE
;
36 static void toolbarcheck( HWND hDlg
)
38 /* test toolbar properties */
45 for( ctrl
= GetWindow( hDlg
, GW_CHILD
);
46 ctrl
; ctrl
= GetWindow( ctrl
, GW_HWNDNEXT
)) {
47 GetClassNameA( ctrl
, classname
, 10);
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
)
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
)
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");
79 ok(buf
[0] == 0x66 && buf
[1] == 0x66, "CMD_GETFOLDERIDLIST: The buffer was touched on failure\n");
80 toolbarcheck( GetParent(hDlg
));
88 static void test_DialogCancel(void)
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
;
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());
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());
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
;
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");
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");
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
;
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");
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
);
205 win_skip("CreateViewWindow2 is broken on Vista/W2K8\n");
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
);
237 if (shell_view2
) IShellView2_Release(shell_view2
);
238 if (shell_view
) IShellView_Release(shell_view
);
239 PostMessageA(GetParent(dlg
), WM_COMMAND
, IDCANCEL
, 0);
245 static UINT_PTR WINAPI
template_hook(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
247 if (msg
== WM_INITDIALOG
)
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);
266 static void test_create_view_window2(void)
268 OPENFILENAMEA ofn
= {0};
269 char filename
[1024] = {0};
272 ofn
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
273 ofn
.lpstrFile
= filename
;
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};
289 ofn
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
290 ofn
.lpstrFile
= filename
;
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 {
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
},
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
);
331 #define MAXNRCTRLS 30
332 static RECT ctrlrcs
[MAXNRCTRLS
];
333 static int ctrlids
[MAXNRCTRLS
];
334 static HWND ctrls
[MAXNRCTRLS
];
343 index
= ((OPENFILENAMEA
*)lParam
)->lCustData
;
345 gotSWP_bottom
= gotShowWindow
= FALSE
;
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);
354 ok( style
& WS_SIZEBOX
,
355 "testid %d: dialog should have a WS_SIZEBOX style.\n", index
);
357 ok( !(style
& WS_SIZEBOX
),
358 "testid %d: dialog should not have a WS_SIZEBOX style.\n", index
);
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);
376 /* store the control rectangles */
377 if( resize_testcases
[index
].testcontrols
) {
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);
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 todo_wine_if( resize_testcases
[index
].todo
){
399 ok( resize
== rc
.right
- rc
.left
- initrc
.right
+ initrc
.left
,
400 "testid %d size-x change %d expected %d\n", index
,
401 rc
.right
- rc
.left
- initrc
.right
+ initrc
.left
, resize
);
402 ok( resize
== rc
.bottom
- rc
.top
- initrc
.bottom
+ initrc
.top
,
403 "testid %d size-y change %d expected %d\n", index
,
404 rc
.bottom
- rc
.top
- initrc
.bottom
+ initrc
.top
, resize
);
406 if( resize_testcases
[index
].testcontrols
) {
409 for( i
= 0; i
< nrctrls
; i
++) {
410 GetWindowRect( ctrls
[i
], &rc
);
411 MapWindowPoints( NULL
, parent
, (LPPOINT
) &rc
, 2);
414 /* test if RECT R1, moved and sized result in R2 */
415 #define TESTRECTS( R1, R2, Mx, My, Sx, Sy) \
416 ((R1).left + (Mx) ==(R2).left \
417 &&(R1).top + (My) ==(R2).top \
418 &&(R1).right + (Mx) + (Sx) == (R2).right \
419 &&(R1).bottom + (My) + (Sy) ==(R2).bottom)
421 /* sized horizontal and moved vertical */
424 ok( TESTRECTS( ctrlrcs
[i
], rc
, 0, 10, 10, 0),
425 "control id %03x should have sized horizontally and moved vertically, before %s after %s\n",
426 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
427 wine_dbgstr_rect( &rc
));
429 /* sized horizontal and vertical */
431 ok( TESTRECTS( ctrlrcs
[i
], rc
, 0, 0, 10, 10),
432 "control id %03x should have sized horizontally and vertically, before %s after %s\n",
433 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
434 wine_dbgstr_rect( &rc
));
436 /* moved horizontal and vertical */
439 ok( TESTRECTS( ctrlrcs
[i
], rc
, 10, 10, 0, 0),
440 "control id %03x should have moved horizontally and vertically, before %s after %s\n",
441 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
442 wine_dbgstr_rect( &rc
));
444 /* moved vertically */
448 ok( TESTRECTS( ctrlrcs
[i
], rc
, 0, 10, 0, 0),
449 "control id %03x should have moved vertically, before %s after %s\n",
450 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
451 wine_dbgstr_rect( &rc
));
453 /* resized horizontal */
454 case cmb2
: /* aka IDC_LOOKIN */
455 ok( TESTRECTS( ctrlrcs
[i
], rc
, 0, 0, 10, 0)||
456 TESTRECTS( ctrlrcs
[i
], rc
, 0, 0, 0, 0), /* Vista and higher */
457 "control id %03x should have resized horizontally, before %s after %s\n",
458 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
459 wine_dbgstr_rect( &rc
));
461 /* non moving non sizing controls */
463 ok( TESTRECTS( rc
, ctrlrcs
[i
], 0, 0, 0, 0),
464 "control id %03x was moved/resized, before %s after %s\n",
465 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
466 wine_dbgstr_rect( &rc
));
468 /* todo_wine: 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 /* don't test: id is not unique */
483 trace("untested control id %03x before %s after %s\n",
484 ctrlids
[i
], wine_dbgstr_rect( &ctrlrcs
[i
] ),
485 wine_dbgstr_rect( &rc
));
492 PostMessageA( parent
, WM_COMMAND
, IDCANCEL
, 0);
497 case WM_WINDOWPOSCHANGING
:
499 WINDOWPOS
*pwp
= (WINDOWPOS
*)lParam
;
500 if( !index
&& pwp
->hwndInsertAfter
== HWND_BOTTOM
){
501 gotSWP_bottom
= TRUE
;
502 ok(!gotShowWindow
, "The WM_WINDOWPOSCHANGING message came after a WM_SHOWWINDOW message\n");
509 gotShowWindow
= TRUE
;
510 ok(gotSWP_bottom
, "No WM_WINDOWPOSCHANGING message came before a WM_SHOWWINDOW message\n");
518 static void test_resize(void)
520 OPENFILENAMEA ofn
= { OPENFILENAME_SIZE_VERSION_400A
};
521 char filename
[1024] = {0};
525 ofn
.lpstrFile
= filename
;
527 ofn
.lpfnHook
= resize_template_hook
;
528 ofn
.hInstance
= GetModuleHandleA(NULL
);
529 ofn
.lpTemplateName
= "template_sz";
530 for( i
= 0; resize_testcases
[i
].flags
!= 0xffffffff; i
++) {
532 ofn
.Flags
= resize_testcases
[i
].flags
|
533 OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
| OFN_SHOWHELP
;
534 ret
= GetOpenFileNameA(&ofn
);
535 ok(!ret
, "GetOpenFileName returned %#x\n", ret
);
536 ret
= CommDlgExtendedError();
537 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
541 /* test cases for control message IDOK */
542 /* Show case for bug #19079 */
544 int retval
; /* return code of the message handler */
545 BOOL setmsgresult
; /* set the result in the DWLP_MSGRESULT */
546 BOOL usemsgokstr
; /* use the FILEOKSTRING message instead of WM_NOTIFY:CDN_FILEOK */
547 BOOL do_subclass
; /* subclass the dialog hook procedure */
548 BOOL expclose
; /* is the dialog expected to close ? */
549 BOOL actclose
; /* has the dialog actually closed ? */
550 } ok_wndproc_testcase
;
552 static ok_wndproc_testcase ok_testcases
[] = {
553 { 0, FALSE
, FALSE
, FALSE
, TRUE
},
554 { 0, TRUE
, FALSE
, FALSE
, TRUE
},
555 { 0, FALSE
, FALSE
, TRUE
, TRUE
},
556 { 0, TRUE
, FALSE
, TRUE
, TRUE
},
557 { 1, FALSE
, FALSE
, FALSE
, TRUE
},
558 { 1, TRUE
, FALSE
, FALSE
, FALSE
},
559 { 1, FALSE
, FALSE
, TRUE
, FALSE
},
560 { 1, TRUE
, FALSE
, TRUE
, FALSE
},
561 /* FILEOKSTRING tests */
562 { 1, TRUE
, TRUE
, FALSE
, FALSE
},
563 { 1, FALSE
, TRUE
, TRUE
, FALSE
},
568 /* test_ok_wndproc can be used as hook procedure or a subclass
569 * window proc for the file dialog */
570 static UINT_PTR WINAPI
test_ok_wndproc(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
572 HWND parent
= GetParent( dlg
);
573 static ok_wndproc_testcase
*testcase
= NULL
;
574 static UINT msgFILEOKSTRING
;
575 if (msg
== WM_INITDIALOG
)
577 testcase
= (ok_wndproc_testcase
*)((OPENFILENAMEA
*)lParam
)->lCustData
;
578 testcase
->actclose
= TRUE
;
579 msgFILEOKSTRING
= RegisterWindowMessageA( FILEOKSTRINGA
);
581 if( msg
== WM_NOTIFY
) {
582 if(((LPNMHDR
)lParam
)->code
== CDN_FOLDERCHANGE
) {
583 SetTimer( dlg
, 0, 100, 0);
584 PostMessageA( parent
, WM_COMMAND
, IDOK
, 0);
586 } else if(((LPNMHDR
)lParam
)->code
== CDN_FILEOK
) {
587 if( testcase
->usemsgokstr
)
589 if( testcase
->setmsgresult
)
590 SetWindowLongPtrA( dlg
, DWLP_MSGRESULT
, testcase
->retval
);
591 return testcase
->retval
;
594 if( msg
== msgFILEOKSTRING
) {
595 if( !testcase
->usemsgokstr
)
597 if( testcase
->setmsgresult
)
598 SetWindowLongPtrA( dlg
, DWLP_MSGRESULT
, testcase
->retval
);
599 return testcase
->retval
;
601 if( msg
== WM_TIMER
) {
602 /* the dialog did not close automatically */
603 testcase
->actclose
= FALSE
;
605 PostMessageA( parent
, WM_COMMAND
, IDCANCEL
, 0);
608 if( testcase
&& testcase
->do_subclass
)
609 return DefWindowProcA( dlg
, msg
, wParam
, lParam
);
613 static UINT_PTR WINAPI
ok_template_hook(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
615 if (msg
== WM_SETFONT
)
616 SetWindowLongPtrA( dlg
, GWLP_WNDPROC
, (LONG_PTR
) test_ok_wndproc
);
620 static void test_ok(void)
622 OPENFILENAMEA ofn
= { OPENFILENAME_SIZE_VERSION_400A
};
623 char filename
[1024] = {0};
624 char tmpfilename
[ MAX_PATH
];
625 char curdir
[MAX_PATH
];
630 cdret
= GetCurrentDirectoryA(sizeof(curdir
), curdir
);
631 ok(cdret
, "Failed to get current dir err %d\n", GetLastError());
632 if (!GetTempFileNameA(".", "txt", 0, tmpfilename
)) {
633 skip("Failed to create a temporary file name\n");
636 ofn
.lpstrFile
= filename
;
638 ofn
.hInstance
= GetModuleHandleA(NULL
);
639 ofn
.lpTemplateName
= "template1";
640 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
;
641 for( i
= 0; ok_testcases
[i
].retval
!= -1; i
++) {
642 strcpy( filename
, tmpfilename
);
643 ofn
.lCustData
= (LPARAM
)(ok_testcases
+ i
);
644 ofn
.lpfnHook
= ok_testcases
[i
].do_subclass
? ok_template_hook
: test_ok_wndproc
;
645 ret
= GetOpenFileNameA(&ofn
);
646 ok( ok_testcases
[i
].expclose
== ok_testcases
[i
].actclose
,
647 "testid %d: Open File dialog should %shave closed.\n", i
,
648 ok_testcases
[i
].expclose
? "" : "NOT ");
649 ok(ret
== ok_testcases
[i
].expclose
, "testid %d: GetOpenFileName returned %#x\n", i
, ret
);
650 ret
= CommDlgExtendedError();
651 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
652 cdret
= SetCurrentDirectoryA(curdir
);
653 ok(cdret
, "Failed to restore current dir err %d\n", GetLastError());
655 ret
= DeleteFileA( tmpfilename
);
656 ok( ret
, "Failed to delete temporary file %s err %d\n", tmpfilename
, GetLastError());
659 /* test arranging with a custom template */
661 int x
, y
; /* left, top coordinates */
662 int cx
, cy
; /* width and height */
665 int nrcontrols
; /* 0: no controls, 1: just the stc32 control 2: with button */
670 } arrange_tests
[] = {
671 /* do not change the first two cases: used to get the uncustomized sizes */
672 { 0, {0},{0},{0},0 },
673 { 0, {0},{0},{0}, OFN_SHOWHELP
},
674 /* two tests with just a subdialog, no controls */
675 { 0, {0, 0, 316, 76},{0},{0},0 },
676 { 0, {0, 0, 100, 76},{0},{0}, OFN_SHOWHELP
},
677 /* now with a control with id stc32 */
678 { 1, {0, 0, 316, 76} ,{0, 0, 204, 76,},{0},0 }, /* bug #17748*/
679 { 1, {0, 0, 316, 76} ,{0, 0, 204, 76,},{0}, OFN_SHOWHELP
}, /* bug #17748*/
680 /* tests with size of the stc32 control higher or wider then the standard dialog */
681 { 1, {0, 0, 316, 170} ,{0, 0, 204, 170,},{0},0 },
682 { 1, {0, 0, 316, 165} ,{0, 0, 411, 165,},{0}, OFN_SHOWHELP
},
683 /* move the stc32 control around */
684 { 1, {0, 0, 300, 100} ,{73, 17, 50, 50,},{0},0 },
686 { 2, {0, 0, 280, 100} ,{0, 0, 50, 50,},{300,20,30,30},0 },
687 /* enable resizing should make the dialog bigger */
688 { 0, {0},{0},{0}, OFN_SHOWHELP
|OFN_ENABLESIZING
},
693 static UINT_PTR WINAPI
template_hook_arrange(HWND dlgChild
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
695 static int index
, fixhelp
;
696 static posz posz0
[2];
697 static RECT clrcParent
, clrcChild
, rcStc32
;
698 static HWND hwndStc32
;
701 dlgParent
= GetParent( dlgChild
);
702 if (msg
== WM_INITDIALOG
) {
703 index
= ((OPENFILENAMEA
*)lParam
)->lCustData
;
704 /* get the positions before rearrangement */
705 GetClientRect( dlgParent
, &clrcParent
);
706 GetClientRect( dlgChild
, &clrcChild
);
707 hwndStc32
= GetDlgItem( dlgChild
, stc32
);
708 if( hwndStc32
) GetWindowRect( hwndStc32
, &rcStc32
);
710 if (msg
== WM_NOTIFY
&& ((LPNMHDR
)lParam
)->code
== CDN_FOLDERCHANGE
) {
713 GetWindowRect( dlgParent
, &wrcParent
);
714 /* the fist two "tests" just save the dialogs position, with and without
717 posz0
[0].x
= wrcParent
.left
;
718 posz0
[0].y
= wrcParent
.top
;
719 posz0
[0].cx
= wrcParent
.right
- wrcParent
.left
;
720 posz0
[0].cy
= wrcParent
.bottom
- wrcParent
.top
;
721 } else if( index
== 1) {
722 posz0
[1].x
= wrcParent
.left
;
723 posz0
[1].y
= wrcParent
.top
;
724 posz0
[1].cx
= wrcParent
.right
- wrcParent
.left
;
725 posz0
[1].cy
= wrcParent
.bottom
- wrcParent
.top
;
726 fixhelp
= posz0
[1].cy
- posz0
[0].cy
;
730 int expectx
, expecty
;
733 withhelp
= (arrange_tests
[index
].ofnflags
& OFN_SHOWHELP
) != 0;
734 GetWindowRect( dlgParent
, &wrcParent
);
736 /* case with no custom subitem with stc32:
737 * default to all custom controls below the standard */
738 expecty
= posz0
[withhelp
].cy
+ clrcChild
.bottom
;
739 expectx
= posz0
[withhelp
].cx
;
741 /* special case: there is a control with id stc32 */
742 /* expected height */
743 expecty
= posz0
[withhelp
].cy
;
744 if( rcStc32
.bottom
- rcStc32
.top
+ (withhelp
? 0 : fixhelp
) > clrcParent
.bottom
) {
745 expecty
+= clrcChild
.bottom
- clrcParent
.bottom
;
746 if( !withhelp
) expecty
+= fixhelp
;
749 expecty
+= clrcChild
.bottom
- ( rcStc32
.bottom
- rcStc32
.top
) ;
751 expectx
= posz0
[withhelp
].cx
;
752 if( rcStc32
.right
- rcStc32
.left
> clrcParent
.right
) {
753 expectx
+= clrcChild
.right
- clrcParent
.right
;
756 expectx
+= clrcChild
.right
- ( rcStc32
.right
- rcStc32
.left
) ;
758 style
= GetWindowLongA( dlgParent
, GWL_STYLE
);
759 if( !(style
& WS_SIZEBOX
)) {
760 /* without the OFN_ENABLESIZING flag */
761 ok( wrcParent
.bottom
- wrcParent
.top
== expecty
,
762 "Wrong height of dialog %d, expected %d\n",
763 wrcParent
.bottom
- wrcParent
.top
, expecty
);
764 ok( wrcParent
.right
- wrcParent
.left
== expectx
,
765 "Wrong width of dialog %d, expected %d\n",
766 wrcParent
.right
- wrcParent
.left
, expectx
);
768 /* with the OFN_ENABLESIZING flag */
769 ok( wrcParent
.bottom
- wrcParent
.top
> expecty
,
770 "Wrong height of dialog %d, expected more than %d\n",
771 wrcParent
.bottom
- wrcParent
.top
, expecty
);
772 ok( wrcParent
.right
- wrcParent
.left
> expectx
,
773 "Wrong width of dialog %d, expected more than %d\n",
774 wrcParent
.right
- wrcParent
.left
, expectx
);
778 PostMessageA( dlgParent
, WM_COMMAND
, IDCANCEL
, 0);
783 static void test_arrange(void)
785 OPENFILENAMEA ofn
= {0};
786 char filename
[1024] = {0};
791 DLGTEMPLATE
*template;
792 DLGITEMTEMPLATE
*itemtemplateStc32
, *itemtemplateBtn
;
795 /* load subdialog template into memory */
796 hRes
= FindResourceA( GetModuleHandleA(NULL
), "template_stc32", (LPSTR
)RT_DIALOG
);
797 hDlgTmpl
= LoadResource( GetModuleHandleA(NULL
), hRes
);
798 /* get pointers to the structures for the dialog and the controls */
799 pv
= LockResource( hDlgTmpl
);
800 template = (DLGTEMPLATE
*)pv
;
801 if( template->x
!= 11111) {
802 win_skip("could not find the dialog template\n");
805 /* skip dialog template, menu, class and title */
806 pv
+= sizeof(DLGTEMPLATE
);
807 pv
+= 3 * sizeof(WORD
);
812 /* align on 32 bit boundaries */
813 pv
= (LPBYTE
)(((UINT_PTR
)pv
+ 3 ) & ~3);
814 itemtemplateStc32
= (DLGITEMTEMPLATE
*)pv
;
815 if( itemtemplateStc32
->x
!= 22222) {
816 win_skip("could not find the first item template\n");
819 /* skip itemtemplate, class, title and creation data */
820 pv
+= sizeof(DLGITEMTEMPLATE
);
821 pv
+= 4 * sizeof(WORD
);
822 /* align on 32 bit boundaries */
823 pv
= (LPBYTE
)(((UINT_PTR
)pv
+ 3 ) & ~3);
824 itemtemplateBtn
= (DLGITEMTEMPLATE
*)pv
;
825 if( itemtemplateBtn
->x
!= 12345) {
826 win_skip("could not find the second item template\n");
830 ofn
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
831 ofn
.lpstrFile
= filename
;
833 ofn
.lpfnHook
= template_hook_arrange
;
834 ofn
.hInstance
= hDlgTmpl
;
835 ofn
.lpstrFilter
="text\0*.txt\0All\0*\0\0";
836 for( i
= 0; arrange_tests
[i
].nrcontrols
!= -1; i
++) {
838 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATEHANDLE
| OFN_HIDEREADONLY
|
839 arrange_tests
[i
].ofnflags
;
840 template->cdit
= arrange_tests
[i
].nrcontrols
;
841 template->x
= arrange_tests
[i
].poszDlg
.x
;
842 template->y
= arrange_tests
[i
].poszDlg
.y
;
843 template->cx
= arrange_tests
[i
].poszDlg
.cx
;
844 template->cy
= arrange_tests
[i
].poszDlg
.cy
;
845 itemtemplateStc32
->x
= arrange_tests
[i
].poszStc32
.x
;
846 itemtemplateStc32
->y
= arrange_tests
[i
].poszStc32
.y
;
847 itemtemplateStc32
->cx
= arrange_tests
[i
].poszStc32
.cx
;
848 itemtemplateStc32
->cy
= arrange_tests
[i
].poszStc32
.cy
;
849 itemtemplateBtn
->x
= arrange_tests
[i
].poszBtn
.x
;
850 itemtemplateBtn
->y
= arrange_tests
[i
].poszBtn
.y
;
851 itemtemplateBtn
->cx
= arrange_tests
[i
].poszBtn
.cx
;
852 itemtemplateBtn
->cy
= arrange_tests
[i
].poszBtn
.cy
;
853 ret
= GetOpenFileNameA(&ofn
);
854 ok(!ret
, "GetOpenFileNameA returned %#x\n", ret
);
855 ret
= CommDlgExtendedError();
856 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
860 static CHAR SYSDIR
[MAX_PATH
];
862 static UINT_PTR CALLBACK
path_hook_proc( HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
866 if( msg
== WM_NOTIFY
)
868 nmh
= (LPNMHDR
) lParam
;
869 if( nmh
->code
== CDN_INITDONE
)
871 PostMessageA( GetParent(hDlg
), WM_COMMAND
, IDCANCEL
, FALSE
);
873 else if ( nmh
->code
== CDN_FOLDERCHANGE
)
878 memset(buf
, 0x66, sizeof(buf
));
879 ret
= SendMessageA( GetParent(hDlg
), CDM_GETFOLDERPATH
, sizeof(buf
), (LPARAM
)buf
);
880 ok(!lstrcmpiA(SYSDIR
, buf
), "Expected '%s', got '%s'\n", SYSDIR
, buf
);
881 ok(lstrlenA(SYSDIR
) + 1 == ret
, "Expected %d, got %d\n", lstrlenA(SYSDIR
) + 1, ret
);
888 static void test_getfolderpath(void)
892 char szFileName
[MAX_PATH
] = "";
893 char szInitialDir
[MAX_PATH
];
895 /* We need to pick a different directory as the other tests because of new
896 * Windows 7 behavior.
898 GetSystemDirectoryA(szInitialDir
, MAX_PATH
);
899 lstrcpyA(SYSDIR
, szInitialDir
);
901 ZeroMemory(&ofn
, sizeof(ofn
));
903 ofn
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
904 ofn
.hwndOwner
= NULL
;
905 ofn
.lpstrFilter
= "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
906 ofn
.lpstrFile
= szFileName
;
907 ofn
.nMaxFile
= MAX_PATH
;
908 ofn
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_ENABLEHOOK
;
909 ofn
.lpstrDefExt
= "txt";
910 ofn
.lpfnHook
= path_hook_proc
;
911 ofn
.lpstrInitialDir
= szInitialDir
;
913 result
= GetOpenFileNameA(&ofn
);
914 ok(FALSE
== result
, "expected FALSE, got %d\n", result
);
915 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
916 CommDlgExtendedError());
918 result
= GetSaveFileNameA(&ofn
);
919 ok(FALSE
== result
, "expected FALSE, got %d\n", result
);
920 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
921 CommDlgExtendedError());
924 static void test_resizable2(void)
926 OPENFILENAMEA ofn
= {0};
927 char filename
[1024] = "pls press Enter if sizable, Esc otherwise";
930 /* interactive because there is no hook function */
931 if( !winetest_interactive
) {
932 skip( "some interactive resizable dialog tests (set WINETEST_INTERACTIVE=1)\n");
935 ofn
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
936 ofn
.lpstrFile
= filename
;
939 ofn
.hInstance
= GetModuleHandleA(NULL
);
940 ofn
.lpTemplateName
= "template1";
941 ofn
.Flags
= OFN_EXPLORER
;
942 ret
= GetOpenFileNameA(&ofn
);
943 ok( ret
== TRUE
, "File Dialog should have been sizable\n");
944 ret
= CommDlgExtendedError();
945 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
946 ofn
.Flags
= OFN_EXPLORER
| OFN_ENABLETEMPLATE
;
947 ret
= GetOpenFileNameA(&ofn
);
948 ok( !ret
, "File Dialog should NOT have been sizable\n");
949 ret
= CommDlgExtendedError();
950 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
951 ofn
.Flags
= OFN_EXPLORER
| OFN_ENABLETEMPLATEHANDLE
;
952 ofn
.hInstance
= LoadResource( GetModuleHandleA(NULL
), FindResourceA( GetModuleHandleA(NULL
), "template1", (LPSTR
)RT_DIALOG
));
953 ofn
.lpTemplateName
= NULL
;
954 ret
= GetOpenFileNameA(&ofn
);
955 ok( !ret
, "File Dialog should NOT have been sizable\n");
956 ret
= CommDlgExtendedError();
957 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
958 ofn
.Flags
= OFN_EXPLORER
| OFN_ENABLEHOOK
;
959 ret
= GetOpenFileNameA(&ofn
);
960 ok( !ret
, "File Dialog should NOT have been sizable\n");
961 ret
= CommDlgExtendedError();
962 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
965 static void test_mru(void)
967 ok_wndproc_testcase testcase
= {0};
968 OPENFILENAMEA ofn
= { OPENFILENAME_SIZE_VERSION_400A
};
969 const char *test_dir_name
= "C:\\mru_test";
970 const char *test_file_name
= "test.txt";
971 const char *test_full_path
= "C:\\mru_test\\test.txt";
972 char filename_buf
[MAX_PATH
];
975 ofn
.lpstrFile
= filename_buf
;
976 ofn
.nMaxFile
= sizeof(filename_buf
);
977 ofn
.lpTemplateName
= "template1";
978 ofn
.hInstance
= GetModuleHandleA(NULL
);
979 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
| OFN_NOCHANGEDIR
;
980 ofn
.lCustData
= (LPARAM
)&testcase
;
981 ofn
.lpfnHook
= test_ok_wndproc
;
983 SetLastError(0xdeadbeef);
984 ret
= CreateDirectoryA(test_dir_name
, NULL
);
985 ok(ret
== TRUE
, "CreateDirectoryA should have succeeded: %d\n", GetLastError());
987 /* "teach" comdlg32 about this directory */
988 strcpy(filename_buf
, test_full_path
);
989 SetLastError(0xdeadbeef);
990 ret
= GetOpenFileNameA(&ofn
);
991 ok(ret
, "GetOpenFileNameA should have succeeded: %d\n", GetLastError());
992 ret
= CommDlgExtendedError();
993 ok(!ret
, "CommDlgExtendedError returned %x\n", ret
);
994 ok(testcase
.actclose
, "Open File dialog should have closed.\n");
995 ok(!strcmp(ofn
.lpstrFile
, test_full_path
), "Expected to get %s, got %s\n", test_full_path
, ofn
.lpstrFile
);
997 /* get a filename without a full path. it should return the file in
998 * test_dir_name, not in the CWD */
999 strcpy(filename_buf
, test_file_name
);
1000 SetLastError(0xdeadbeef);
1001 ret
= GetOpenFileNameA(&ofn
);
1002 ok(ret
, "GetOpenFileNameA should have succeeded: %d\n", GetLastError());
1003 ret
= CommDlgExtendedError();
1004 ok(!ret
, "CommDlgExtendedError returned %x\n", ret
);
1005 ok(testcase
.actclose
, "Open File dialog should have closed.\n");
1006 if(strcmp(ofn
.lpstrFile
, test_full_path
) != 0)
1007 win_skip("Platform doesn't save MRU data\n");
1009 SetLastError(0xdeadbeef);
1010 ret
= RemoveDirectoryA(test_dir_name
);
1011 ok(ret
== TRUE
, "RemoveDirectoryA should have succeeded: %d\n", GetLastError());
1014 static UINT_PTR WINAPI
test_extension_wndproc(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1016 HWND parent
= GetParent( dlg
);
1017 if( msg
== WM_NOTIFY
) {
1018 SetTimer( dlg
, 0, 1000, 0);
1019 PostMessageA( parent
, WM_COMMAND
, IDOK
, 0);
1021 if( msg
== WM_TIMER
) {
1022 /* the dialog did not close automatically */
1024 PostMessageA( parent
, WM_COMMAND
, IDCANCEL
, 0);
1029 static void test_extension_helper(OPENFILENAMEA
* ofn
, const char *filter
,
1030 const char *expected_filename
)
1036 strcpy(ofn
->lpstrFile
, "deadbeef");
1037 ofn
->lpstrFilter
= filter
;
1039 boolret
= GetSaveFileNameA(ofn
);
1040 ok(boolret
, "%s: expected TRUE\n", filter
);
1042 ret
= CommDlgExtendedError();
1043 ok(!ret
, "%s: CommDlgExtendedError returned %#x\n", filter
, ret
);
1045 filename_ptr
= ofn
->lpstrFile
+ ofn
->nFileOffset
;
1046 ok(strcmp(filename_ptr
, expected_filename
) == 0,
1047 "%s: Filename is %s, expected %s\n", filter
, filename_ptr
, expected_filename
);
1050 static void test_extension(void)
1052 OPENFILENAMEA ofn
= { OPENFILENAME_SIZE_VERSION_400A
};
1053 char filename
[1024] = {0};
1058 const char *defext_concrete_filters
[] = {
1059 "TestFilter (*.abc)\0*.abc\0",
1060 "TestFilter (*.abc;)\0*.abc;\0",
1061 "TestFilter (*.abc;*.def)\0*.abc;*.def\0",
1064 const char *defext_wildcard_filters
[] = {
1065 "TestFilter (*.pt*)\0*.pt*\0",
1066 "TestFilter (*.pt*;*.abc)\0*.pt*;*.abc\0",
1067 "TestFilter (*.ab?)\0*.ab?\0",
1068 "TestFilter (*.*)\0*.*\0",
1069 "TestFilter (*sav)\0*sav\0",
1070 NULL
/* is a test, not an endmark! */
1073 boolret
= GetTempPathA(sizeof(dir
), dir
);
1074 ok(boolret
, "Failed to get current dir err %d\n", GetLastError());
1076 ofn
.hwndOwner
= NULL
;
1077 ofn
.lpstrFile
= filename
;
1078 ofn
.nMaxFile
= MAX_PATH
;
1079 ofn
.Flags
= OFN_EXPLORER
| OFN_ENABLEHOOK
;
1080 ofn
.lpstrInitialDir
= dir
;
1081 ofn
.lpfnHook
= test_extension_wndproc
;
1082 ofn
.nFileExtension
= 0;
1084 ofn
.lpstrDefExt
= NULL
;
1086 /* Without lpstrDefExt, append no extension */
1087 test_extension_helper(&ofn
, "TestFilter (*.abc) lpstrDefExt=NULL\0*.abc\0", "deadbeef");
1088 test_extension_helper(&ofn
, "TestFilter (*.ab?) lpstrDefExt=NULL\0*.ab?\0", "deadbeef");
1090 ofn
.lpstrDefExt
= "";
1092 /* If lpstrDefExt="" and the filter has a concrete extension, append it */
1093 test_extension_helper(&ofn
, "TestFilter (*.abc) lpstrDefExt=\"\"\0*.abc\0", "deadbeef.abc");
1095 /* If lpstrDefExt="" and the filter has a wildcard extension, do nothing */
1096 test_extension_helper(&ofn
, "TestFilter (*.ab?) lpstrDefExt=\"\"\0*.ab?\0", "deadbeef");
1098 ofn
.lpstrDefExt
= "xyz";
1100 /* Append concrete extensions from filters */
1101 for (i
= 0; i
< ARRAY_SIZE(defext_concrete_filters
); i
++) {
1102 test_extension_helper(&ofn
, defext_concrete_filters
[i
], "deadbeef.abc");
1105 /* Append nothing from this filter */
1106 test_extension_helper(&ofn
, "TestFilter (*.)\0*.\0", "deadbeef");
1108 /* Ignore wildcard extensions in filters */
1109 for (i
= 0; i
< ARRAY_SIZE(defext_wildcard_filters
); i
++) {
1110 test_extension_helper(&ofn
, defext_wildcard_filters
[i
], "deadbeef.xyz");
1113 /* Append valid extensions consisting of multiple parts */
1114 test_extension_helper(&ofn
, "TestFilter (*.abc.def)\0*.abc.def\0", "deadbeef.abc.def");
1115 test_extension_helper(&ofn
, "TestFilter (.abc.def)\0.abc.def\0", "deadbeef.abc.def");
1116 test_extension_helper(&ofn
, "TestFilter (*.*.def)\0*.*.def\0", "deadbeef.xyz");
1119 static BOOL WINAPI
test_null_enum(HWND hwnd
, LPARAM lParam
)
1121 /* Find the textbox and send a filename so IDOK will work.
1122 If the file textbox is empty IDOK will be ignored */
1124 if(GetClassNameA(hwnd
, className
, sizeof(className
)) > 0 && !strcmp("Edit",className
))
1126 SetWindowTextA(hwnd
, "testfile");
1127 return FALSE
; /* break window enumeration */
1132 static UINT_PTR WINAPI
test_null_wndproc(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1134 HWND parent
= GetParent( dlg
);
1135 if( msg
== WM_NOTIFY
) {
1136 SetTimer( dlg
, 0, 100, 0);
1137 SetTimer( dlg
, 1, 1000, 0);
1138 EnumChildWindows( parent
, test_null_enum
, 0);
1140 if( msg
== WM_TIMER
) {
1142 PostMessageA( parent
, WM_COMMAND
, IDOK
, 0);
1144 /* the dialog did not close automatically */
1146 PostMessageA( parent
, WM_COMMAND
, IDCANCEL
, 0);
1152 static void test_null_filename(void)
1154 OPENFILENAMEA ofnA
= {0};
1155 OPENFILENAMEW ofnW
= {0};
1156 WCHAR filterW
[] = {'t','e','x','t','\0','*','.','t','x','t','\0',
1157 'A','l','l','\0','*','\0','\0'};
1160 ofnA
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
1161 ofnA
.lpstrFile
= NULL
;
1163 ofnA
.nFileOffset
= 0xdead;
1164 ofnA
.nFileExtension
= 0xbeef;
1165 ofnA
.lpfnHook
= test_null_wndproc
;
1166 ofnA
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
;
1167 ofnA
.hInstance
= GetModuleHandleA(NULL
);
1168 ofnA
.lpstrFilter
= "text\0*.txt\0All\0*\0\0";
1169 ofnA
.lpstrDefExt
= NULL
;
1170 ret
= GetOpenFileNameA(&ofnA
);
1171 todo_wine
ok(ret
, "GetOpenFileNameA returned %#x\n", ret
);
1172 ret
= CommDlgExtendedError();
1173 todo_wine
ok(!ret
, "CommDlgExtendedError returned %#x, should be 0\n", ret
);
1175 todo_wine
ok(ofnA
.nFileOffset
!= 0xdead, "ofnA.nFileOffset is 0xdead\n");
1176 todo_wine
ok(ofnA
.nFileExtension
!= 0xbeef, "ofnA.nFileExtension is 0xbeef\n");
1178 ofnA
.lpstrFile
= NULL
;
1179 ofnA
.nMaxFile
= 1024; /* bogus input - lpstrFile = NULL but fake 1024 bytes available */
1180 ofnA
.nFileOffset
= 0xdead;
1181 ofnA
.nFileExtension
= 0xbeef;
1182 ret
= GetOpenFileNameA(&ofnA
);
1183 ok(ret
, "GetOpenFileNameA returned %#x\n", ret
);
1184 ret
= CommDlgExtendedError();
1185 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
1187 ok(ofnA
.nFileOffset
!= 0xdead, "ofnA.nFileOffset is 0xdead\n");
1188 ok(ofnA
.nFileExtension
== 0, "ofnA.nFileExtension is 0x%x, should be 0\n", ofnA
.nFileExtension
);
1191 ofnW
.lStructSize
= OPENFILENAME_SIZE_VERSION_400W
;
1192 ofnW
.lpstrFile
= NULL
;
1194 ofnW
.nFileOffset
= 0xdead;
1195 ofnW
.nFileExtension
= 0xbeef;
1196 ofnW
.lpfnHook
= test_null_wndproc
;
1197 ofnW
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
;
1198 ofnW
.hInstance
= GetModuleHandleW(NULL
);
1199 ofnW
.lpstrFilter
= filterW
;
1200 ofnW
.lpstrDefExt
= NULL
;
1201 ret
= GetOpenFileNameW(&ofnW
);
1202 todo_wine
ok(ret
, "GetOpenFileNameW returned %#x\n", ret
);
1203 ret
= CommDlgExtendedError();
1204 todo_wine
ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
1206 todo_wine
ok(ofnW
.nFileOffset
!= 0xdead, "ofnW.nFileOffset is 0xdead\n");
1207 todo_wine
ok(ofnW
.nFileExtension
!= 0xbeef, "ofnW.nFileExtension is 0xbeef\n");
1209 ofnW
.lpstrFile
= NULL
;
1210 ofnW
.nMaxFile
= 1024; /* bogus input - lpstrFile = NULL but fake 1024 bytes available */
1211 ofnW
.nFileOffset
= 0xdead;
1212 ofnW
.nFileExtension
= 0xbeef;
1213 ret
= GetOpenFileNameW(&ofnW
);
1214 ok(ret
, "GetOpenFileNameA returned %#x\n", ret
);
1215 ret
= CommDlgExtendedError();
1216 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
1218 ok(ofnW
.nFileOffset
!= 0xdead, "ofnW.nFileOffset is 0xdead\n");
1219 ok(ofnW
.nFileExtension
== 0, "ofnW.nFileExtension is 0x%x, should be 0\n", ofnW
.nFileExtension
);
1222 static void test_directory_filename(void)
1224 OPENFILENAMEA ofnA
= {0};
1225 OPENFILENAMEW ofnW
= {0};
1226 WCHAR filterW
[] = {'t','e','x','t','\0','*','.','t','x','t','\0',
1227 'A','l','l','\0','*','\0','\0'};
1228 char szInitialDir
[MAX_PATH
] = {0};
1229 WCHAR szInitialDirW
[MAX_PATH
] = {0};
1232 GetWindowsDirectoryA(szInitialDir
, MAX_PATH
);
1233 GetWindowsDirectoryW(szInitialDirW
, MAX_PATH
);
1235 szInitialDir
[strlen(szInitialDir
)] = '\\';
1236 szInitialDirW
[lstrlenW(szInitialDirW
)] = '\\';
1238 ofnA
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
1239 ofnA
.lpstrFile
= szInitialDir
;
1240 ofnA
.nMaxFile
= MAX_PATH
;
1241 ofnA
.lpfnHook
= test_null_wndproc
;
1242 ofnA
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
;
1243 ofnA
.hInstance
= GetModuleHandleA(NULL
);
1244 ofnA
.lpstrFilter
= "text\0*.txt\0All\0*\0\0";
1245 ofnA
.lpstrDefExt
= NULL
;
1246 ret
= GetOpenFileNameA(&ofnA
);
1247 todo_wine
ok(!ret
, "GetOpenFileNameA returned %#x\n", ret
);
1250 ofnW
.lStructSize
= OPENFILENAME_SIZE_VERSION_400W
;
1251 ofnW
.lpstrFile
= szInitialDirW
;
1252 ofnW
.nMaxFile
= MAX_PATH
;
1253 ofnW
.lpfnHook
= test_null_wndproc
;
1254 ofnW
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
;
1255 ofnW
.hInstance
= GetModuleHandleW(NULL
);
1256 ofnW
.lpstrFilter
= filterW
;
1257 ofnW
.lpstrDefExt
= NULL
;
1258 ret
= GetOpenFileNameW(&ofnW
);
1259 todo_wine
ok(!ret
, "GetOpenFileNameW returned %#x\n", ret
);
1262 static UINT_PTR WINAPI
test_ole_init_wndproc(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1266 hr
= OleInitialize(NULL
);
1267 ok(hr
== S_FALSE
, "OleInitialize() returned %#x\n", hr
);
1270 if (msg
== WM_NOTIFY
)
1271 PostMessageA(GetParent(dlg
), WM_COMMAND
, IDCANCEL
, 0);
1275 static LRESULT CALLBACK
hook_proc(int code
, WPARAM wp
, LPARAM lp
)
1277 static BOOL first_dlg
= TRUE
;
1280 if (code
== HCBT_CREATEWND
)
1282 CBT_CREATEWNDW
*c
= (CBT_CREATEWNDW
*)lp
;
1284 if (c
->lpcs
->lpszClass
== (LPWSTR
)WC_DIALOG
)
1286 /* OleInitialize() creates a window for the main apartment. Since
1287 * Vista OleInitialize() is called before the file dialog is
1288 * created. SimCity 2000 expects that the first window created
1289 * after GetOpenFileA() is a file dialog window. Mark Vista+
1290 * behavior as broken. */
1291 hr
= OleInitialize(NULL
);
1292 ok((first_dlg
? hr
== S_OK
: hr
== S_FALSE
)
1293 || broken(first_dlg
&& hr
== S_FALSE
),
1294 "OleInitialize() returned %#x (first dialog %#x)\n", hr
, first_dlg
);
1300 return CallNextHookEx(NULL
, code
, wp
, lp
);
1303 static void test_ole_initialization(void)
1305 char file
[MAX_PATH
] = {0};
1306 OPENFILENAMEA ofn
= {0};
1311 hook
= SetWindowsHookExW(WH_CBT
, hook_proc
, NULL
, GetCurrentThreadId());
1313 ofn
.lStructSize
= OPENFILENAME_SIZE_VERSION_400A
;
1314 ofn
.lpstrFile
= file
;
1315 ofn
.nMaxFile
= MAX_PATH
;
1316 ofn
.lpfnHook
= test_ole_init_wndproc
;
1317 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
;
1318 ofn
.hInstance
= GetModuleHandleA(NULL
);
1319 ret
= GetOpenFileNameA(&ofn
);
1320 ok(!ret
, "GetOpenFileNameA returned %#x\n", ret
);
1322 hr
= OleInitialize(NULL
);
1323 ok(hr
== S_OK
, "OleInitialize() returned %#x\n", hr
);
1326 UnhookWindowsHookEx(hook
);
1331 test_DialogCancel();
1332 test_create_view_window2();
1333 test_create_view_template();
1337 test_getfolderpath();
1339 if( resizesupported
) test_resizable2();
1341 test_null_filename();
1342 test_directory_filename();
1343 test_ole_initialization();