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>
32 static void toolbarcheck( HWND hDlg
)
34 /* test toolbar properties */
41 for( ctrl
= GetWindow( hDlg
, GW_CHILD
);
42 ctrl
; ctrl
= GetWindow( ctrl
, GW_HWNDNEXT
)) {
43 GetClassName( ctrl
, classname
, 10);
45 if( !strcmp( classname
, "Toolbar")) break;
47 ok( ctrl
!= NULL
, "could not get the toolbar control\n");
48 ret
= SendMessage( ctrl
, TB_ADDSTRING
, 0, (LPARAM
)"winetestwinetest\0\0");
49 ok( ret
== 0, "addstring returned %d (expected 0)\n", ret
);
50 maxtextrows
= SendMessage( ctrl
, TB_GETTEXTROWS
, 0, 0);
51 ok( maxtextrows
== 0 || broken(maxtextrows
== 1), /* Win2k and below */
52 "Get(Max)TextRows returned %d (expected 0)\n", maxtextrows
);
56 static UINT_PTR CALLBACK
OFNHookProc( HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
62 nmh
= (LPNMHDR
) lParam
;
63 if( nmh
->code
== CDN_INITDONE
)
65 PostMessage( GetParent(hDlg
), WM_COMMAND
, IDCANCEL
, FALSE
);
66 } else if (nmh
->code
== CDN_FOLDERCHANGE
)
71 memset(buf
, 0x66, sizeof(buf
));
72 ret
= SendMessage( GetParent(hDlg
), CDM_GETFOLDERIDLIST
, 5, (LPARAM
)buf
);
73 ok(ret
> 0, "CMD_GETFOLDERIDLIST not implemented\n");
75 ok(buf
[0] == 0x66 && buf
[1] == 0x66, "CMD_GETFOLDERIDLIST: The buffer was touched on failure\n");
76 toolbarcheck( GetParent(hDlg
));
84 static void test_DialogCancel(void)
88 char szFileName
[MAX_PATH
] = "";
89 char szInitialDir
[MAX_PATH
];
91 GetWindowsDirectory(szInitialDir
, MAX_PATH
);
93 ZeroMemory(&ofn
, sizeof(ofn
));
95 ofn
.lStructSize
= sizeof(ofn
);
97 ofn
.lpstrFilter
= "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
98 ofn
.lpstrFile
= szFileName
;
99 ofn
.nMaxFile
= MAX_PATH
;
100 ofn
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_ENABLEHOOK
;
101 ofn
.lpstrDefExt
= "txt";
102 ofn
.lpfnHook
= OFNHookProc
;
103 ofn
.lpstrInitialDir
= szInitialDir
;
106 ok(CDERR_INITIALIZATION
== CommDlgExtendedError(),
107 "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
109 result
= GetOpenFileNameA(&ofn
);
110 ok(0 == result
, "expected 0, got %d\n", result
);
111 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
112 CommDlgExtendedError());
115 ok(CDERR_INITIALIZATION
== CommDlgExtendedError(),
116 "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
118 result
= GetSaveFileNameA(&ofn
);
119 ok(0 == result
, "expected 0, got %d\n", result
);
120 ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
121 CommDlgExtendedError());
124 ok(CDERR_INITIALIZATION
== CommDlgExtendedError(),
125 "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
127 /* Before passing the ofn to Unicode functions, remove the ANSI strings */
128 ofn
.lpstrFilter
= NULL
;
129 ofn
.lpstrInitialDir
= NULL
;
130 ofn
.lpstrDefExt
= NULL
;
133 ok(CDERR_INITIALIZATION
== CommDlgExtendedError(),
134 "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());
136 SetLastError(0xdeadbeef);
137 result
= GetOpenFileNameW((LPOPENFILENAMEW
) &ofn
);
138 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
139 win_skip("GetOpenFileNameW is not implemented\n");
142 ok(0 == result
, "expected 0, got %d\n", result
);
143 ok(0 == CommDlgExtendedError() ||
144 broken(CDERR_INITIALIZATION
== CommDlgExtendedError()), /* win9x */
145 "expected 0, got %d\n", CommDlgExtendedError());
148 SetLastError(0xdeadbeef);
149 result
= GetSaveFileNameW((LPOPENFILENAMEW
) &ofn
);
150 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
151 win_skip("GetSaveFileNameW is not implemented\n");
154 ok(0 == result
, "expected 0, got %d\n", result
);
155 ok(0 == CommDlgExtendedError() ||
156 broken(CDERR_INITIALIZATION
== CommDlgExtendedError()), /* win9x */
157 "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
*)SendMessage(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 Win9x and 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
||
233 broken(folder_settings
.ViewMode
== FVM_LIST
), /* Win9x */
234 "view mode is %d, expected FVM_DETAILS\n",
235 folder_settings
.ViewMode
);
238 if (shell_view2
) IShellView2_Release(shell_view2
);
239 if (shell_view
) IShellView_Release(shell_view
);
240 PostMessage(GetParent(dlg
), WM_COMMAND
, IDCANCEL
, 0);
246 static LONG_PTR WINAPI
template_hook(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
248 if (msg
== WM_INITDIALOG
)
253 ok(p
!=NULL
, "Failed to get parent of template\n");
254 cb
= GetDlgItem(p
,0x470);
255 ok(cb
!=NULL
, "Failed to get filter combobox\n");
256 sel
= SendMessage(cb
, CB_GETCURSEL
, 0, 0);
257 ok (sel
!= -1, "Failed to get selection from filter listbox\n");
259 if (msg
== WM_NOTIFY
)
261 if (((LPNMHDR
)lParam
)->code
== CDN_FOLDERCHANGE
)
262 PostMessage(GetParent(dlg
), WM_COMMAND
, IDCANCEL
, 0);
267 static void test_create_view_window2(void)
269 OPENFILENAMEA ofn
= {0};
270 char filename
[1024] = {0};
273 ofn
.lStructSize
= sizeof(ofn
);
274 ofn
.lpstrFile
= filename
;
276 ofn
.lpfnHook
= create_view_window2_hook
;
277 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
;
278 ret
= GetOpenFileNameA(&ofn
);
279 ok(!ret
, "GetOpenFileNameA returned %#x\n", ret
);
280 ret
= CommDlgExtendedError();
281 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
284 static void test_create_view_template(void)
286 OPENFILENAMEA ofn
= {0};
287 char filename
[1024] = {0};
290 ofn
.lStructSize
= sizeof(ofn
);
291 ofn
.lpstrFile
= filename
;
293 ofn
.lpfnHook
= (LPOFNHOOKPROC
)template_hook
;
294 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
;
295 ofn
.hInstance
= GetModuleHandleA(NULL
);
296 ofn
.lpTemplateName
= "template1";
297 ofn
.lpstrFilter
="text\0*.txt\0All\0*\0\0";
298 ret
= GetOpenFileNameA(&ofn
);
299 ok(!ret
, "GetOpenFileNameA returned %#x\n", ret
);
300 ret
= CommDlgExtendedError();
301 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
304 /* test cases for resizing of the file dialog */
307 int resize_folderchange
;/* change in CDN_FOLDERCHANGE handler */
308 int resize_timer1
; /* change in first WM_TIMER handler */
309 int resize_check
; /* expected change (in second WM_TIMER handler) */
310 BOOL todo
; /* mark that test todo_wine */
311 BOOL testcontrols
; /* test resizing and moving of the controls */
312 } resize_testcases
[] = {
313 { 0 , 10, 10, 20,FALSE
,FALSE
}, /* 0 */
314 { 0 ,-10,-10,-20,FALSE
,FALSE
},
315 { OFN_ENABLESIZING
, 0, 0, 0,FALSE
,FALSE
},
316 { OFN_ENABLESIZING
, 0,-10, 0,FALSE
,FALSE
},
317 { OFN_ENABLESIZING
, 0, 10, 10,FALSE
, TRUE
},
318 { OFN_ENABLESIZING
,-10, 0, 10,FALSE
,FALSE
}, /* 5 */
319 { OFN_ENABLESIZING
, 10, 0, 10,FALSE
,FALSE
},
320 { OFN_ENABLESIZING
, 0, 10, 20,FALSE
,FALSE
},
325 static LONG_PTR WINAPI
resize_template_hook(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
327 static RECT initrc
, rc
;
328 static int index
, count
;
329 static int gotSWP_bottom
, gotShowWindow
;
330 HWND parent
= GetParent( dlg
);
332 #define MAXNRCTRLS 30
333 static RECT ctrlrcs
[MAXNRCTRLS
];
334 static int ctrlids
[MAXNRCTRLS
];
335 static HWND ctrls
[MAXNRCTRLS
];
344 index
= ((OPENFILENAME
*)lParam
)->lCustData
;
346 gotSWP_bottom
= gotShowWindow
= 0;
348 style
= GetWindowLong( parent
, GWL_STYLE
);
349 if( resize_testcases
[index
].flags
& OFN_ENABLESIZING
)
350 if( !(style
& WS_SIZEBOX
)) {
351 win_skip( "OFN_ENABLESIZING flag not supported.\n");
352 PostMessage( 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 if( resize_testcases
[index
].todo
){
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
);
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
) {
418 for( i
= 0; i
< nrctrls
; i
++) {
419 GetWindowRect( ctrls
[i
], &rc
);
420 MapWindowPoints( NULL
, parent
, (LPPOINT
) &rc
, 2);
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 */
433 ok( TESTRECTS( ctrlrcs
[i
], rc
, 0, 10, 10, 0) ||
434 broken(TESTRECTS( ctrlrcs
[i
], rc
, 0, 10, 0, 0)),/*win98*/
435 "control id %03x should have sized horizontally and moved vertically, before %d,%d-%d,%d after %d,%d-%d,%d\n",
436 ctrlids
[i
], ctrlrcs
[i
].left
, ctrlrcs
[i
].top
,
437 ctrlrcs
[i
].right
, ctrlrcs
[i
].bottom
,
438 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
440 /* sized horizontal and vertical */
442 ok( TESTRECTS( ctrlrcs
[i
], rc
, 0, 0, 10, 10),
443 "control id %03x should have sized horizontally and vertically, before %d,%d-%d,%d after %d,%d-%d,%d\n",
444 ctrlids
[i
], ctrlrcs
[i
].left
, ctrlrcs
[i
].top
,
445 ctrlrcs
[i
].right
, ctrlrcs
[i
].bottom
,
446 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
448 /* moved horizontal and vertical */
451 ok( TESTRECTS( ctrlrcs
[i
], rc
, 10, 10, 0, 0) ||
452 broken(TESTRECTS( ctrlrcs
[i
], rc
, 0, 10, 0, 0)),/*win98*/
453 "control id %03x should have moved horizontally and vertically, before %d,%d-%d,%d after %d,%d-%d,%d\n",
454 ctrlids
[i
], ctrlrcs
[i
].left
, ctrlrcs
[i
].top
,
455 ctrlrcs
[i
].right
, ctrlrcs
[i
].bottom
,
456 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
458 /* moved vertically */
462 ok( TESTRECTS( ctrlrcs
[i
], rc
, 0, 10, 0, 0),
463 "control id %03x should have moved vertically, before %d,%d-%d,%d after %d,%d-%d,%d\n",
464 ctrlids
[i
], ctrlrcs
[i
].left
, ctrlrcs
[i
].top
,
465 ctrlrcs
[i
].right
, ctrlrcs
[i
].bottom
,
466 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
468 /* resized horizontal */
469 case cmb2
: /* aka IDC_LOOKIN */
470 ok( TESTRECTS( ctrlrcs
[i
], rc
, 0, 0, 10, 0)||
471 TESTRECTS( ctrlrcs
[i
], rc
, 0, 0, 0, 0), /* Vista and higher */
472 "control id %03x should have resized horizontally, before %d,%d-%d,%d after %d,%d-%d,%d\n",
473 ctrlids
[i
], ctrlrcs
[i
].left
, ctrlrcs
[i
].top
,
474 ctrlrcs
[i
].right
, ctrlrcs
[i
].bottom
,
475 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
477 /* non moving non sizing controls */
479 ok( TESTRECTS( rc
, ctrlrcs
[i
], 0, 0, 0, 0),
480 "control id %03x was moved/resized, before %d,%d-%d,%d after %d,%d-%d,%d\n",
481 ctrlids
[i
], ctrlrcs
[i
].left
, ctrlrcs
[i
].top
,
482 ctrlrcs
[i
].right
, ctrlrcs
[i
].bottom
,
483 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
485 /* todo_wine: non moving non sizing controls */
488 ok( TESTRECTS( rc
, ctrlrcs
[i
], 0, 0, 0, 0),
489 "control id %03x was moved/resized, before %d,%d-%d,%d after %d,%d-%d,%d\n",
490 ctrlids
[i
], ctrlrcs
[i
].left
, ctrlrcs
[i
].top
,
491 ctrlrcs
[i
].right
, ctrlrcs
[i
].bottom
,
492 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
494 /* don't test: id is not unique */
501 trace("untested control id %03x before %d,%d-%d,%d after %d,%d-%d,%d\n",
502 ctrlids
[i
], ctrlrcs
[i
].left
, ctrlrcs
[i
].top
,
503 ctrlrcs
[i
].right
, ctrlrcs
[i
].bottom
,
504 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
511 PostMessage( parent
, WM_COMMAND
, IDCANCEL
, 0);
516 case WM_WINDOWPOSCHANGING
:
518 WINDOWPOS
*pwp
= (WINDOWPOS
*)lParam
;
519 if( !index
&& pwp
->hwndInsertAfter
== HWND_BOTTOM
){
521 ok( gotShowWindow
== 0, "The WM_WINDOWPOSCHANGING message came after a WM_SHOWWINDOW message\n");
529 ok( gotSWP_bottom
== 1, "No WM_WINDOWPOSCHANGING message came before a WM_SHOWWINDOW message\n");
537 static void test_resize(void)
539 OPENFILENAME ofn
= { sizeof(OPENFILENAME
)};
540 char filename
[1024] = {0};
544 ofn
.lpstrFile
= filename
;
546 ofn
.lpfnHook
= (LPOFNHOOKPROC
) resize_template_hook
;
547 ofn
.hInstance
= GetModuleHandle(NULL
);
548 ofn
.lpTemplateName
= "template_sz";
549 for( i
= 0; resize_testcases
[i
].flags
!= 0xffffffff; i
++) {
551 ofn
.Flags
= resize_testcases
[i
].flags
|
552 OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
| OFN_SHOWHELP
;
553 ret
= GetOpenFileName(&ofn
);
554 ok(!ret
, "GetOpenFileName returned %#x\n", ret
);
555 ret
= CommDlgExtendedError();
556 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
560 /* test cases for control message IDOK */
561 /* Show case for bug #19079 */
563 int retval
; /* return code of the message handler */
564 BOOL setmsgresult
; /* set the result in the DWLP_MSGRESULT */
565 BOOL usemsgokstr
; /* use the FILEOKSTRING message instead of WM_NOTIFY:CDN_FILEOK */
566 BOOL do_subclass
; /* subclass the dialog hook procedure */
567 BOOL expclose
; /* is the dialog expected to close ? */
568 BOOL actclose
; /* has the dialog actually closed ? */
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
},
585 /* test_ok_wndproc can be used as hook procedure or a subclass
586 * window proc for the file dialog */
587 static LONG_PTR WINAPI
test_ok_wndproc(HWND dlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
589 HWND parent
= GetParent( dlg
);
591 static UINT msgFILEOKSTRING
;
592 if (msg
== WM_INITDIALOG
)
594 index
= ((OPENFILENAME
*)lParam
)->lCustData
;
595 ok_testcases
[index
].actclose
= TRUE
;
596 msgFILEOKSTRING
= RegisterWindowMessageA( FILEOKSTRING
);
598 if( msg
== WM_NOTIFY
) {
599 if(((LPNMHDR
)lParam
)->code
== CDN_FOLDERCHANGE
) {
600 SetTimer( dlg
, 0, 100, 0);
601 PostMessage( parent
, WM_COMMAND
, IDOK
, 0);
603 } else if(((LPNMHDR
)lParam
)->code
== CDN_FILEOK
) {
604 if( ok_testcases
[index
].usemsgokstr
)
606 if( ok_testcases
[index
].setmsgresult
)
607 SetWindowLongPtrA( dlg
, DWLP_MSGRESULT
, ok_testcases
[index
].retval
);
608 return ok_testcases
[index
].retval
;
611 if( msg
== msgFILEOKSTRING
) {
612 if( !ok_testcases
[index
].usemsgokstr
)
614 if( ok_testcases
[index
].setmsgresult
)
615 SetWindowLongPtrA( dlg
, DWLP_MSGRESULT
, ok_testcases
[index
].retval
);
616 return ok_testcases
[index
].retval
;
618 if( msg
== WM_TIMER
) {
619 /* the dialog did not close automatically */
620 ok_testcases
[index
].actclose
= FALSE
;
622 PostMessage( parent
, WM_COMMAND
, IDCANCEL
, 0);
625 if( ok_testcases
[index
].do_subclass
)
626 return DefWindowProc( dlg
, msg
, wParam
, lParam
);
630 static LONG_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
);
637 static void test_ok(void)
639 OPENFILENAME ofn
= { sizeof(OPENFILENAME
)};
640 char filename
[1024] = {0};
641 char tmpfilename
[ MAX_PATH
];
642 char curdir
[MAX_PATH
];
646 ok(GetCurrentDirectoryA(sizeof(curdir
), curdir
) != 0, "Failed to get current dir err %d\n", GetLastError());
647 if (!GetTempFileNameA(".", "txt", 0, tmpfilename
)) {
648 skip("Failed to create a temporary file name\n");
651 ofn
.lpstrFile
= filename
;
653 ofn
.hInstance
= GetModuleHandle(NULL
);
654 ofn
.lpTemplateName
= "template1";
655 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
;
656 for( i
= 0; ok_testcases
[i
].retval
!= -1; i
++) {
657 strcpy( filename
, tmpfilename
);
659 ofn
.lpfnHook
= ok_testcases
[i
].do_subclass
660 ? (LPOFNHOOKPROC
) ok_template_hook
661 : (LPOFNHOOKPROC
) 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 ok(SetCurrentDirectoryA(curdir
), "Failed to restore current dir err %d\n", GetLastError());
671 ret
= DeleteFileA( tmpfilename
);
672 ok( ret
, "Failed to delete temporary file %s err %d\n", tmpfilename
, GetLastError());
675 /* test arranging with a custom template */
677 int x
, y
; /* left, top coordinates */
678 int cx
, cy
; /* width and height */
681 int nrcontrols
; /* 0: no controls, 1: just the stc32 control 2: with button */
686 } arrange_tests
[] = {
687 /* do not change the first two cases: used to get the uncustomized sizes */
688 { 0, {0},{0},{0},0 },
689 { 0, {0},{0},{0}, OFN_SHOWHELP
},
690 /* two tests with just a subdialog, no controls */
691 { 0, {0, 0, 316, 76},{0},{0},0 },
692 { 0, {0, 0, 100, 76},{0},{0}, OFN_SHOWHELP
},
693 /* now with a control with id stc32 */
694 { 1, {0, 0, 316, 76} ,{0, 0, 204, 76,},{0},0 }, /* bug #17748*/
695 { 1, {0, 0, 316, 76} ,{0, 0, 204, 76,},{0}, OFN_SHOWHELP
}, /* bug #17748*/
696 /* tests with size of the stc32 control higher or wider then the standard dialog */
697 { 1, {0, 0, 316, 170} ,{0, 0, 204, 170,},{0},0 },
698 { 1, {0, 0, 316, 165} ,{0, 0, 411, 165,},{0}, OFN_SHOWHELP
},
699 /* move the stc32 control around */
700 { 1, {0, 0, 300, 100} ,{73, 17, 50, 50,},{0},0 },
702 { 2, {0, 0, 280, 100} ,{0, 0, 50, 50,},{300,20,30,30},0 },
703 /* enable resizing should make the dialog bigger */
704 { 0, {0},{0},{0}, OFN_SHOWHELP
|OFN_ENABLESIZING
},
709 static LONG_PTR WINAPI
template_hook_arrange(HWND dlgChild
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
711 static int index
, fixhelp
;
712 static posz posz0
[2];
713 static RECT clrcParent
, clrcChild
, rcStc32
;
714 static HWND hwndStc32
;
717 dlgParent
= GetParent( dlgChild
);
718 if (msg
== WM_INITDIALOG
) {
719 index
= ((OPENFILENAME
*)lParam
)->lCustData
;
720 /* get the positions before rearrangement */
721 GetClientRect( dlgParent
, &clrcParent
);
722 GetClientRect( dlgChild
, &clrcChild
);
723 hwndStc32
= GetDlgItem( dlgChild
, stc32
);
724 if( hwndStc32
) GetWindowRect( hwndStc32
, &rcStc32
);
726 if (msg
== WM_NOTIFY
&& ((LPNMHDR
)lParam
)->code
== CDN_FOLDERCHANGE
) {
729 GetWindowRect( dlgParent
, &wrcParent
);
730 /* the fist two "tests" just save the dialogs position, with and without
733 posz0
[0].x
= wrcParent
.left
;
734 posz0
[0].y
= wrcParent
.top
;
735 posz0
[0].cx
= wrcParent
.right
- wrcParent
.left
;
736 posz0
[0].cy
= wrcParent
.bottom
- wrcParent
.top
;
737 } else if( index
== 1) {
738 posz0
[1].x
= wrcParent
.left
;
739 posz0
[1].y
= wrcParent
.top
;
740 posz0
[1].cx
= wrcParent
.right
- wrcParent
.left
;
741 posz0
[1].cy
= wrcParent
.bottom
- wrcParent
.top
;
742 fixhelp
= posz0
[1].cy
- posz0
[0].cy
;
746 int expectx
, expecty
;
749 withhelp
= (arrange_tests
[index
].ofnflags
& OFN_SHOWHELP
) != 0;
750 GetWindowRect( dlgParent
, &wrcParent
);
752 /* case with no custom subitem with stc32:
753 * default to all custom controls below the standard */
754 expecty
= posz0
[withhelp
].cy
+ clrcChild
.bottom
;
755 expectx
= posz0
[withhelp
].cx
;
757 /* special case: there is a control with id stc32 */
758 /* expected height */
759 expecty
= posz0
[withhelp
].cy
;
760 if( rcStc32
.bottom
- rcStc32
.top
> clrcParent
.bottom
) {
761 expecty
+= clrcChild
.bottom
- clrcParent
.bottom
;
762 if( !withhelp
) expecty
+= fixhelp
;
765 expecty
+= clrcChild
.bottom
- ( rcStc32
.bottom
- rcStc32
.top
) ;
767 expectx
= posz0
[withhelp
].cx
;
768 if( rcStc32
.right
- rcStc32
.left
> clrcParent
.right
) {
769 expectx
+= clrcChild
.right
- clrcParent
.right
;
772 expectx
+= clrcChild
.right
- ( rcStc32
.right
- rcStc32
.left
) ;
774 style
= GetWindowLong( dlgParent
, GWL_STYLE
);
775 if( !(style
& WS_SIZEBOX
)) {
776 /* without the OFN_ENABLESIZING flag */
777 ok( wrcParent
.bottom
- wrcParent
.top
== expecty
,
778 "Wrong height of dialog %d, expected %d\n",
779 wrcParent
.bottom
- wrcParent
.top
, expecty
);
780 ok( wrcParent
.right
- wrcParent
.left
== expectx
,
781 "Wrong width of dialog %d, expected %d\n",
782 wrcParent
.right
- wrcParent
.left
, expectx
);
784 /* with the OFN_ENABLESIZING flag */
785 ok( wrcParent
.bottom
- wrcParent
.top
> expecty
,
786 "Wrong height of dialog %d, expected more than %d\n",
787 wrcParent
.bottom
- wrcParent
.top
, expecty
);
788 ok( wrcParent
.right
- wrcParent
.left
> expectx
,
789 "Wrong width of dialog %d, expected more than %d\n",
790 wrcParent
.right
- wrcParent
.left
, expectx
);
794 PostMessage( dlgParent
, WM_COMMAND
, IDCANCEL
, 0);
799 static void test_arrange(void)
801 OPENFILENAMEA ofn
= {0};
802 char filename
[1024] = {0};
807 DLGTEMPLATE
*template;
808 DLGITEMTEMPLATE
*itemtemplateStc32
, *itemtemplateBtn
;
811 /* load subdialog template into memory */
812 hRes
= FindResource( GetModuleHandle(NULL
), "template_stc32", (LPSTR
)RT_DIALOG
);
813 hDlgTmpl
= LoadResource( GetModuleHandle(NULL
), hRes
);
814 /* get pointers to the structures for the dialog and the controls */
815 pv
= LockResource( hDlgTmpl
);
816 template = (DLGTEMPLATE
*)pv
;
817 if( template->x
!= 11111) {
818 win_skip("could not find the dialog template\n");
821 /* skip dialog template, menu, class and title */
822 pv
+= sizeof(DLGTEMPLATE
);
823 pv
+= 3 * sizeof(WORD
);
828 /* align on 32 bit boundaries */
829 pv
= (LPBYTE
)(((UINT_PTR
)pv
+ 3 ) & ~3);
830 itemtemplateStc32
= (DLGITEMTEMPLATE
*)pv
;
831 if( itemtemplateStc32
->x
!= 22222) {
832 win_skip("could not find the first item template\n");
835 /* skip itemtemplate, class, title and creation data */
836 pv
+= sizeof(DLGITEMTEMPLATE
);
837 pv
+= 4 * sizeof(WORD
);
838 /* align on 32 bit boundaries */
839 pv
= (LPBYTE
)(((UINT_PTR
)pv
+ 3 ) & ~3);
840 itemtemplateBtn
= (DLGITEMTEMPLATE
*)pv
;
841 if( itemtemplateBtn
->x
!= 12345) {
842 win_skip("could not find the second item template\n");
846 ofn
.lStructSize
= sizeof(ofn
);
847 ofn
.lpstrFile
= filename
;
849 ofn
.lpfnHook
= (LPOFNHOOKPROC
)template_hook_arrange
;
850 ofn
.hInstance
= hDlgTmpl
;
851 ofn
.lpstrFilter
="text\0*.txt\0All\0*\0\0";
852 for( i
= 0; arrange_tests
[i
].nrcontrols
!= -1; i
++) {
854 ofn
.Flags
= OFN_ENABLEHOOK
| OFN_EXPLORER
| OFN_ENABLETEMPLATEHANDLE
| OFN_HIDEREADONLY
|
855 arrange_tests
[i
].ofnflags
;
856 template->cdit
= arrange_tests
[i
].nrcontrols
;
857 template->x
= arrange_tests
[i
].poszDlg
.x
;
858 template->y
= arrange_tests
[i
].poszDlg
.y
;
859 template->cx
= arrange_tests
[i
].poszDlg
.cx
;
860 template->cy
= arrange_tests
[i
].poszDlg
.cy
;
861 itemtemplateStc32
->x
= arrange_tests
[i
].poszStc32
.x
;
862 itemtemplateStc32
->y
= arrange_tests
[i
].poszStc32
.y
;
863 itemtemplateStc32
->cx
= arrange_tests
[i
].poszStc32
.cx
;
864 itemtemplateStc32
->cy
= arrange_tests
[i
].poszStc32
.cy
;
865 itemtemplateBtn
->x
= arrange_tests
[i
].poszBtn
.x
;
866 itemtemplateBtn
->y
= arrange_tests
[i
].poszBtn
.y
;
867 itemtemplateBtn
->cx
= arrange_tests
[i
].poszBtn
.cx
;
868 itemtemplateBtn
->cy
= arrange_tests
[i
].poszBtn
.cy
;
869 ret
= GetOpenFileNameA(&ofn
);
870 ok(!ret
, "GetOpenFileNameA returned %#x\n", ret
);
871 ret
= CommDlgExtendedError();
872 ok(!ret
, "CommDlgExtendedError returned %#x\n", ret
);
879 test_create_view_window2();
880 test_create_view_template();