2 * Unit tests for the Common Item Dialog
4 * Copyright 2010,2011 David Hedberg
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
26 #include "wine/test.h"
28 #define IDT_CHANGEFILETYPE 500
29 #define IDT_CLOSEDIALOG 501
32 IFDEVENT_TEST_NONE
= 0,
36 } FileDialogEventsTest
;
38 static HRESULT (WINAPI
*pSHCreateShellItem
)(LPCITEMIDLIST
,IShellFolder
*,LPCITEMIDLIST
,IShellItem
**);
39 static HRESULT (WINAPI
*pSHGetIDListFromObject
)(IUnknown
*, PIDLIST_ABSOLUTE
*);
40 static HRESULT (WINAPI
*pSHCreateItemFromParsingName
)(PCWSTR
,IBindCtx
*,REFIID
,void**);
42 static void init_function_pointers(void)
44 HMODULE hmod
= GetModuleHandleA("shell32.dll");
46 #define MAKEFUNC(f) (p##f = (void*)GetProcAddress(hmod, #f))
47 MAKEFUNC(SHCreateShellItem
);
48 MAKEFUNC(SHGetIDListFromObject
);
49 MAKEFUNC(SHCreateItemFromParsingName
);
54 DEFINE_GUID(IID_IFileDialogCustomizeAlt
, 0x8016B7B3, 0x3D49, 0x4504, 0xA0,0xAA, 0x2A,0x37,0x49,0x4E,0x60,0x6F);
61 static BOOL CALLBACK
find_window_callback(HWND hwnd
, LPARAM lparam
)
63 struct fw_arg
*arg
= (struct fw_arg
*)lparam
;
68 GetClassNameW(hwnd
, buf
, 1024);
69 if(lstrcmpW(buf
, arg
->class))
75 GetWindowTextW(hwnd
, buf
, 1024);
76 if(lstrcmpW(buf
, arg
->text
))
84 static HWND
find_window(HWND parent
, LPCWSTR
class, LPCWSTR text
)
86 struct fw_arg arg
= {class, text
, NULL
};
88 EnumChildWindows(parent
, find_window_callback
, (LPARAM
)&arg
);
92 static HWND
get_hwnd_from_ifiledialog(IFileDialog
*pfd
)
98 hr
= IFileDialog_QueryInterface(pfd
, &IID_IOleWindow
, (void**)&pow
);
99 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
101 hr
= IOleWindow_GetWindow(pow
, &dlg_hwnd
);
102 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
104 IOleWindow_Release(pow
);
109 static void test_customize_onfolderchange(IFileDialog
*pfd
);
110 static void filedialog_change_filetype(IFileDialog
*pfd
, HWND dlg_hwnd
);
112 /**************************************************************************
113 * IFileDialogEvents implementation
116 IFileDialogEvents IFileDialogEvents_iface
;
119 LONG OnFileOk
, OnFolderChanging
, OnFolderChange
;
120 LONG OnSelectionChange
, OnShareViolation
, OnTypeChange
;
122 LPCWSTR set_filename
;
123 BOOL set_filename_tried
;
124 FileDialogEventsTest events_test
;
125 } IFileDialogEventsImpl
;
127 static inline IFileDialogEventsImpl
*impl_from_IFileDialogEvents(IFileDialogEvents
*iface
)
129 return CONTAINING_RECORD(iface
, IFileDialogEventsImpl
, IFileDialogEvents_iface
);
132 static HRESULT WINAPI
IFileDialogEvents_fnQueryInterface(IFileDialogEvents
*iface
, REFIID riid
, void **ppv
)
135 ok(0, "Unexpectedly called.\n");
136 return E_NOINTERFACE
;
139 static ULONG WINAPI
IFileDialogEvents_fnAddRef(IFileDialogEvents
*iface
)
141 IFileDialogEventsImpl
*This
= impl_from_IFileDialogEvents(iface
);
142 return InterlockedIncrement(&This
->ref
);
145 static ULONG WINAPI
IFileDialogEvents_fnRelease(IFileDialogEvents
*iface
)
147 IFileDialogEventsImpl
*This
= impl_from_IFileDialogEvents(iface
);
148 LONG ref
= InterlockedDecrement(&This
->ref
);
151 HeapFree(GetProcessHeap(), 0, This
);
156 static HRESULT WINAPI
IFileDialogEvents_fnOnFileOk(IFileDialogEvents
*iface
, IFileDialog
*pfd
)
158 IFileDialogEventsImpl
*This
= impl_from_IFileDialogEvents(iface
);
163 static HRESULT WINAPI
IFileDialogEvents_fnOnFolderChanging(IFileDialogEvents
*iface
,
165 IShellItem
*psiFolder
)
167 IFileDialogEventsImpl
*This
= impl_from_IFileDialogEvents(iface
);
168 This
->OnFolderChanging
++;
172 static LRESULT CALLBACK
test_customize_dlgproc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
174 WNDPROC oldwndproc
= GetPropA(hwnd
, "WT_OLDWC");
175 IFileDialog
*pfd
= GetPropA(hwnd
, "WT_PFD");
181 test_customize_onfolderchange(pfd
);
186 case IDT_CHANGEFILETYPE
:
187 filedialog_change_filetype(pfd
, hwnd
);
188 KillTimer(hwnd
, IDT_CHANGEFILETYPE
);
189 SetTimer(hwnd
, IDT_CLOSEDIALOG
, 100, 0);
191 case IDT_CLOSEDIALOG
:
192 /* Calling IFileDialog_Close here does not work */
193 br
= PostMessageW(hwnd
, WM_COMMAND
, IDCANCEL
, 0);
199 return CallWindowProcW(oldwndproc
, hwnd
, message
, wparam
, lparam
);
202 static HRESULT WINAPI
IFileDialogEvents_fnOnFolderChange(IFileDialogEvents
*iface
, IFileDialog
*pfd
)
204 IFileDialogEventsImpl
*This
= impl_from_IFileDialogEvents(iface
);
208 This
->OnFolderChange
++;
210 if(This
->set_filename
)
212 dlg_hwnd
= get_hwnd_from_ifiledialog(pfd
);
213 ok(dlg_hwnd
!= NULL
, "Got NULL.\n");
215 hr
= IFileDialog_SetFileName(pfd
, This
->set_filename
);
216 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
218 if(!This
->set_filename_tried
)
220 br
= PostMessageW(dlg_hwnd
, WM_COMMAND
, IDOK
, 0);
222 This
->set_filename_tried
= TRUE
;
226 if(This
->events_test
)
230 dlg_hwnd
= get_hwnd_from_ifiledialog(pfd
);
232 /* On Vista, the custom control area of the dialog is not
233 * fully set up when the first OnFolderChange event is
235 oldwndproc
= (WNDPROC
)GetWindowLongPtrW(dlg_hwnd
, GWLP_WNDPROC
);
236 SetPropA(dlg_hwnd
, "WT_OLDWC", (HANDLE
)oldwndproc
);
237 SetPropA(dlg_hwnd
, "WT_PFD", (HANDLE
)pfd
);
238 SetWindowLongPtrW(dlg_hwnd
, GWLP_WNDPROC
, (LPARAM
)test_customize_dlgproc
);
240 switch(This
->events_test
)
243 br
= PostMessageW(dlg_hwnd
, WM_USER
+0x1234, 0, 0);
247 SetTimer(dlg_hwnd
, IDT_CLOSEDIALOG
, 100, 0);
250 SetTimer(dlg_hwnd
, IDT_CHANGEFILETYPE
, 100, 0);
253 ok(FALSE
, "Should not happen (%d)\n", This
->events_test
);
260 static HRESULT WINAPI
IFileDialogEvents_fnOnSelectionChange(IFileDialogEvents
*iface
, IFileDialog
*pfd
)
262 IFileDialogEventsImpl
*This
= impl_from_IFileDialogEvents(iface
);
263 This
->OnSelectionChange
++;
267 static HRESULT WINAPI
IFileDialogEvents_fnOnShareViolation(IFileDialogEvents
*iface
,
270 FDE_SHAREVIOLATION_RESPONSE
*pResponse
)
272 IFileDialogEventsImpl
*This
= impl_from_IFileDialogEvents(iface
);
273 This
->OnShareViolation
++;
277 static HRESULT WINAPI
IFileDialogEvents_fnOnTypeChange(IFileDialogEvents
*iface
, IFileDialog
*pfd
)
279 IFileDialogEventsImpl
*This
= impl_from_IFileDialogEvents(iface
);
280 This
->OnTypeChange
++;
284 static HRESULT WINAPI
IFileDialogEvents_fnOnOverwrite(IFileDialogEvents
*iface
,
287 FDE_OVERWRITE_RESPONSE
*pResponse
)
289 IFileDialogEventsImpl
*This
= impl_from_IFileDialogEvents(iface
);
291 ok(*pResponse
== FDEOR_DEFAULT
, "overwrite response %u\n", *pResponse
);
292 *pResponse
= FDEOR_ACCEPT
;
293 ok(!This
->OnFileOk
, "OnFileOk already called %u times\n", This
->OnFileOk
);
297 static const IFileDialogEventsVtbl vt_IFileDialogEvents
= {
298 IFileDialogEvents_fnQueryInterface
,
299 IFileDialogEvents_fnAddRef
,
300 IFileDialogEvents_fnRelease
,
301 IFileDialogEvents_fnOnFileOk
,
302 IFileDialogEvents_fnOnFolderChanging
,
303 IFileDialogEvents_fnOnFolderChange
,
304 IFileDialogEvents_fnOnSelectionChange
,
305 IFileDialogEvents_fnOnShareViolation
,
306 IFileDialogEvents_fnOnTypeChange
,
307 IFileDialogEvents_fnOnOverwrite
310 static IFileDialogEvents
*IFileDialogEvents_Constructor(void)
312 IFileDialogEventsImpl
*This
;
314 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IFileDialogEventsImpl
));
315 This
->IFileDialogEvents_iface
.lpVtbl
= &vt_IFileDialogEvents
;
318 return &This
->IFileDialogEvents_iface
;
321 static BOOL
test_instantiation(void)
324 IFileOpenDialog
*pfod
;
325 IFileSaveDialog
*pfsd
;
326 IServiceProvider
*psp
;
328 IUnknown
*punk
, *unk2
;
332 /* Instantiate FileOpenDialog */
333 hr
= CoCreateInstance(&CLSID_FileOpenDialog
, NULL
, CLSCTX_INPROC_SERVER
,
334 &IID_IFileOpenDialog
, (void**)&pfod
);
337 win_skip("Could not instantiate the FileOpenDialog.\n");
340 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
342 hr
= IFileOpenDialog_QueryInterface(pfod
, &IID_IFileDialog
, (void**)&pfd
);
343 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
344 if(SUCCEEDED(hr
)) IFileDialog_Release(pfd
);
346 hr
= IFileOpenDialog_QueryInterface(pfod
, &IID_IFileDialogCustomize
, (void**)&punk
);
347 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
349 hr
= IFileOpenDialog_QueryInterface(pfod
, &IID_IFileDialogCustomizeAlt
, (void**)&unk2
);
350 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
351 ok(punk
== unk2
, "got %p, %p\n", punk
, unk2
);
352 IUnknown_Release(punk
);
353 IUnknown_Release(unk2
);
355 hr
= IFileOpenDialog_QueryInterface(pfod
, &IID_IFileSaveDialog
, (void**)&pfsd
);
356 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
357 if(SUCCEEDED(hr
)) IFileSaveDialog_Release(pfsd
);
359 hr
= IFileOpenDialog_QueryInterface(pfod
, &IID_IServiceProvider
, (void**)&psp
);
360 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
363 IExplorerBrowser
*peb
;
366 hr
= IServiceProvider_QueryService(psp
, &SID_SExplorerBrowserFrame
, &IID_ICommDlgBrowser
, (void**)&punk
);
367 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
368 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
370 /* since win8, the result is E_NOTIMPL for all other services */
371 hr
= IServiceProvider_QueryService(psp
, &SID_STopLevelBrowser
, &IID_IExplorerBrowser
, (void**)&peb
);
372 ok(hr
== E_NOTIMPL
|| broken(hr
== E_FAIL
), "got 0x%08x (expected E_NOTIMPL)\n", hr
);
373 if(SUCCEEDED(hr
)) IExplorerBrowser_Release(peb
);
374 hr
= IServiceProvider_QueryService(psp
, &SID_STopLevelBrowser
, &IID_IShellBrowser
, (void**)&psb
);
375 ok(hr
== E_NOTIMPL
|| broken(hr
== E_FAIL
), "got 0x%08x (expected E_NOTIMPL)\n", hr
);
376 if(SUCCEEDED(hr
)) IShellBrowser_Release(psb
);
377 hr
= IServiceProvider_QueryService(psp
, &SID_STopLevelBrowser
, &IID_ICommDlgBrowser
, (void**)&punk
);
378 ok(hr
== E_NOTIMPL
|| broken(hr
== E_FAIL
), "got 0x%08x (expected E_NOTIMPL)\n", hr
);
379 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
381 hr
= IServiceProvider_QueryService(psp
, &SID_STopLevelBrowser
, &IID_IUnknown
, (void**)&punk
);
382 ok(hr
== E_NOTIMPL
|| broken(hr
== E_FAIL
), "got 0x%08x (expected E_NOTIMPL)\n", hr
);
383 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
384 hr
= IServiceProvider_QueryService(psp
, &IID_IUnknown
, &IID_IUnknown
, (void**)&punk
);
385 ok(hr
== E_NOTIMPL
|| broken(hr
== E_FAIL
), "got 0x%08x (expected E_NOTIMPL)\n", hr
);
386 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
388 IServiceProvider_Release(psp
);
391 hr
= IFileOpenDialog_QueryInterface(pfod
, &IID_IFileDialogEvents
, (void**)&punk
);
392 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
393 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
395 hr
= IFileOpenDialog_QueryInterface(pfod
, &IID_IExplorerBrowser
, (void**)&punk
);
396 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
397 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
399 hr
= IFileOpenDialog_QueryInterface(pfod
, &IID_IExplorerBrowserEvents
, (void**)&punk
);
400 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
401 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
403 hr
= IFileOpenDialog_QueryInterface(pfod
, &IID_ICommDlgBrowser3
, (void**)&punk
);
404 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
405 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
407 hr
= IFileOpenDialog_QueryInterface(pfod
, &IID_IShellBrowser
, (void**)&punk
);
408 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
409 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
411 hr
= IFileOpenDialog_QueryInterface(pfod
, &IID_IOleWindow
, (void**)&pow
);
412 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
417 hr
= IOleWindow_ContextSensitiveHelp(pow
, TRUE
);
418 todo_wine
ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
420 hr
= IOleWindow_ContextSensitiveHelp(pow
, FALSE
);
421 todo_wine
ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
425 /* Crashes on win7 */
426 IOleWindow_GetWindow(pow
, NULL
);
429 hr
= IOleWindow_GetWindow(pow
, &hwnd
);
430 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
431 ok(hwnd
== NULL
, "Got %p\n", hwnd
);
433 IOleWindow_Release(pow
);
436 ref
= IFileOpenDialog_Release(pfod
);
437 ok(!ref
, "Got refcount %d, should have been released.\n", ref
);
439 /* Instantiate FileSaveDialog */
440 hr
= CoCreateInstance(&CLSID_FileSaveDialog
, NULL
, CLSCTX_INPROC_SERVER
,
441 &IID_IFileSaveDialog
, (void**)&pfsd
);
444 skip("Could not instantiate the FileSaveDialog.\n");
447 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
449 hr
= IFileSaveDialog_QueryInterface(pfsd
, &IID_IFileDialog
, (void**)&pfd
);
450 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
451 if(SUCCEEDED(hr
)) IFileDialog_Release(pfd
);
453 hr
= IFileSaveDialog_QueryInterface(pfsd
, &IID_IFileDialogCustomize
, (void**)&punk
);
454 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
456 hr
= IFileSaveDialog_QueryInterface(pfsd
, &IID_IFileDialogCustomizeAlt
, (void**)&unk2
);
457 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
458 ok(punk
== unk2
, "got %p, %p\n", punk
, unk2
);
459 IUnknown_Release(punk
);
460 IUnknown_Release(unk2
);
462 hr
= IFileSaveDialog_QueryInterface(pfsd
, &IID_IFileOpenDialog
, (void**)&pfod
);
463 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
464 if(SUCCEEDED(hr
)) IFileOpenDialog_Release(pfod
);
466 hr
= IFileSaveDialog_QueryInterface(pfsd
, &IID_IFileDialogEvents
, (void**)&punk
);
467 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
468 if(SUCCEEDED(hr
)) IFileDialog_Release(pfd
);
470 hr
= IFileSaveDialog_QueryInterface(pfsd
, &IID_IExplorerBrowser
, (void**)&punk
);
471 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
472 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
474 hr
= IFileSaveDialog_QueryInterface(pfsd
, &IID_IExplorerBrowserEvents
, (void**)&punk
);
475 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
476 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
478 hr
= IFileSaveDialog_QueryInterface(pfsd
, &IID_ICommDlgBrowser3
, (void**)&punk
);
479 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
480 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
482 hr
= IFileSaveDialog_QueryInterface(pfsd
, &IID_IShellBrowser
, (void**)&punk
);
483 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
484 if(SUCCEEDED(hr
)) IUnknown_Release(punk
);
486 hr
= IFileSaveDialog_QueryInterface(pfsd
, &IID_IOleWindow
, (void**)&pow
);
487 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
492 hr
= IOleWindow_ContextSensitiveHelp(pow
, TRUE
);
493 todo_wine
ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
495 hr
= IOleWindow_ContextSensitiveHelp(pow
, FALSE
);
496 todo_wine
ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
500 /* Crashes on win7 */
501 IOleWindow_GetWindow(pow
, NULL
);
504 hr
= IOleWindow_GetWindow(pow
, &hwnd
);
505 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
506 ok(hwnd
== NULL
, "Got %p\n", hwnd
);
508 IOleWindow_Release(pow
);
512 ref
= IFileSaveDialog_Release(pfsd
);
513 ok(!ref
, "Got refcount %d, should have been released.\n", ref
);
517 static void test_basics(void)
519 IFileOpenDialog
*pfod
;
520 IFileSaveDialog
*pfsd
;
522 FILEOPENDIALOGOPTIONS fdoptions
;
523 IShellFolder
*psfdesktop
;
524 IShellItem
*psi
, *psidesktop
, *psi_original
;
525 IShellItemArray
*psia
;
532 const WCHAR txt
[] = {'t','x','t', 0};
533 const WCHAR null
[] = {0};
534 const WCHAR fname1
[] = {'f','n','a','m','e','1', 0};
535 const WCHAR fspec1
[] = {'*','.','t','x','t',0};
536 const WCHAR fname2
[] = {'f','n','a','m','e','2', 0};
537 const WCHAR fspec2
[] = {'*','.','e','x','e',0};
538 COMDLG_FILTERSPEC filterspec
[2] = {{fname1
, fspec1
}, {fname2
, fspec2
}};
540 /* This should work on every platform with IFileDialog */
541 SHGetDesktopFolder(&psfdesktop
);
542 hr
= pSHGetIDListFromObject((IUnknown
*)psfdesktop
, &pidl
);
545 hr
= pSHCreateShellItem(NULL
, NULL
, pidl
, &psidesktop
);
548 IShellFolder_Release(psfdesktop
);
551 skip("Failed to get ShellItem from DesktopFolder, skipping tests.\n");
556 /* Instantiate FileOpenDialog and FileSaveDialog */
557 hr
= CoCreateInstance(&CLSID_FileOpenDialog
, NULL
, CLSCTX_INPROC_SERVER
,
558 &IID_IFileOpenDialog
, (void**)&pfod
);
559 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
560 hr
= CoCreateInstance(&CLSID_FileSaveDialog
, NULL
, CLSCTX_INPROC_SERVER
,
561 &IID_IFileSaveDialog
, (void**)&pfsd
);
562 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
564 /* ClearClientData */
567 hr
= IFileOpenDialog_ClearClientData(pfod
);
568 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
569 hr
= IFileSaveDialog_ClearClientData(pfsd
);
570 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
574 hr
= IFileOpenDialog_GetOptions(pfod
, NULL
);
575 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
576 hr
= IFileSaveDialog_GetOptions(pfsd
, NULL
);
577 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
579 /* Check default options */
580 hr
= IFileOpenDialog_GetOptions(pfod
, &fdoptions
);
581 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
582 ok(fdoptions
== (FOS_PATHMUSTEXIST
| FOS_FILEMUSTEXIST
| FOS_NOCHANGEDIR
),
583 "Unexpected default options: 0x%08x\n", fdoptions
);
584 hr
= IFileSaveDialog_GetOptions(pfsd
, &fdoptions
);
585 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
586 ok(fdoptions
== (FOS_OVERWRITEPROMPT
| FOS_NOREADONLYRETURN
| FOS_PATHMUSTEXIST
| FOS_NOCHANGEDIR
),
587 "Unexpected default options: 0x%08x\n", fdoptions
);
590 hr
= IFileOpenDialog_GetResult(pfod
, NULL
);
591 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
592 hr
= IFileSaveDialog_GetResult(pfsd
, NULL
);
593 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
595 psi
= (void*)0xdeadbeef;
596 hr
= IFileOpenDialog_GetResult(pfod
, &psi
);
597 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
598 ok(psi
== (void*)0xdeadbeef, "got %p.\n", psi
);
599 psi
= (void*)0xdeadbeef;
600 hr
= IFileSaveDialog_GetResult(pfsd
, &psi
);
601 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
602 ok(psi
== (void*)0xdeadbeef, "got %p.\n", psi
);
604 /* GetCurrentSelection */
606 /* Crashes on Vista/W2K8. Tests below passes on Windows 7 */
607 hr
= IFileOpenDialog_GetCurrentSelection(pfod
, NULL
);
608 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
609 hr
= IFileSaveDialog_GetCurrentSelection(pfsd
, NULL
);
610 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
611 hr
= IFileOpenDialog_GetCurrentSelection(pfod
, &psi
);
612 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
613 hr
= IFileSaveDialog_GetCurrentSelection(pfsd
, &psi
);
614 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
618 hr
= IFileOpenDialog_GetFileName(pfod
, NULL
);
619 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
620 filename
= (void*)0xdeadbeef;
621 hr
= IFileOpenDialog_GetFileName(pfod
, &filename
);
622 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
623 ok(filename
== NULL
, "got %p\n", filename
);
624 hr
= IFileSaveDialog_GetFileName(pfsd
, NULL
);
625 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
626 filename
= (void*)0xdeadbeef;
627 hr
= IFileSaveDialog_GetFileName(pfsd
, &filename
);
628 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
629 ok(filename
== NULL
, "got %p\n", filename
);
631 /* GetFileTypeIndex */
632 hr
= IFileOpenDialog_GetFileTypeIndex(pfod
, NULL
);
633 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
635 hr
= IFileOpenDialog_GetFileTypeIndex(pfod
, &filetype
);
636 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
637 ok(filetype
== 0, "got %d.\n", filetype
);
638 hr
= IFileSaveDialog_GetFileTypeIndex(pfsd
, NULL
);
639 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
641 hr
= IFileSaveDialog_GetFileTypeIndex(pfsd
, &filetype
);
642 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
643 ok(filetype
== 0, "got %d.\n", filetype
);
645 /* SetFileTypes / SetFileTypeIndex */
646 hr
= IFileOpenDialog_SetFileTypes(pfod
, 0, NULL
);
647 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
648 hr
= IFileOpenDialog_SetFileTypes(pfod
, 0, filterspec
);
649 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
651 hr
= IFileOpenDialog_SetFileTypeIndex(pfod
, 0);
652 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
653 hr
= IFileOpenDialog_SetFileTypeIndex(pfod
, 1);
654 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
655 hr
= IFileOpenDialog_SetFileTypes(pfod
, 1, filterspec
);
656 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
657 hr
= IFileOpenDialog_SetFileTypes(pfod
, 0, filterspec
);
658 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
659 hr
= IFileOpenDialog_SetFileTypeIndex(pfod
, 0);
660 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
661 hr
= IFileOpenDialog_GetFileTypeIndex(pfod
, &filetype
);
662 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
663 ok(filetype
== 1, "got %d\n", filetype
);
664 hr
= IFileOpenDialog_SetFileTypeIndex(pfod
, 100);
665 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
666 hr
= IFileOpenDialog_GetFileTypeIndex(pfod
, &filetype
);
667 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
668 ok(filetype
== 1, "got %d\n", filetype
);
669 hr
= IFileOpenDialog_SetFileTypes(pfod
, 1, filterspec
);
670 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
671 hr
= IFileOpenDialog_SetFileTypes(pfod
, 1, &filterspec
[1]);
672 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
674 hr
= IFileSaveDialog_SetFileTypeIndex(pfsd
, 0);
675 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
676 hr
= IFileSaveDialog_SetFileTypeIndex(pfsd
, 1);
677 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
678 hr
= IFileSaveDialog_SetFileTypes(pfsd
, 2, filterspec
);
679 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
680 hr
= IFileSaveDialog_GetFileTypeIndex(pfsd
, &filetype
);
681 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
682 /* I hope no one relies on this one */
683 todo_wine
ok(filetype
== 0, "got %d\n", filetype
);
684 hr
= IFileSaveDialog_SetFileTypeIndex(pfsd
, 0);
685 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
686 hr
= IFileSaveDialog_GetFileTypeIndex(pfsd
, &filetype
);
687 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
688 ok(filetype
== 1, "got %d\n", filetype
);
689 hr
= IFileSaveDialog_SetFileTypeIndex(pfsd
, 100);
690 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
691 hr
= IFileSaveDialog_GetFileTypeIndex(pfsd
, &filetype
);
692 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
693 ok(filetype
== 2, "got %d\n", filetype
);
694 hr
= IFileSaveDialog_SetFileTypes(pfsd
, 1, filterspec
);
695 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
696 hr
= IFileSaveDialog_SetFileTypes(pfsd
, 1, &filterspec
[1]);
697 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
702 hr
= IFileOpenDialog_SetFilter(pfod
, NULL
);
703 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
704 hr
= IFileSaveDialog_SetFilter(pfsd
, NULL
);
705 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
709 hr
= IFileOpenDialog_SetFolder(pfod
, NULL
);
710 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
711 hr
= IFileSaveDialog_SetFolder(pfsd
, NULL
);
712 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
714 /* SetDefaultExtension */
715 hr
= IFileOpenDialog_SetDefaultExtension(pfod
, NULL
);
716 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
717 hr
= IFileOpenDialog_SetDefaultExtension(pfod
, txt
);
718 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
719 hr
= IFileOpenDialog_SetDefaultExtension(pfod
, null
);
720 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
722 hr
= IFileSaveDialog_SetDefaultExtension(pfsd
, NULL
);
723 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
724 hr
= IFileSaveDialog_SetDefaultExtension(pfsd
, txt
);
725 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
726 hr
= IFileSaveDialog_SetDefaultExtension(pfsd
, null
);
727 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
729 /* SetDefaultFolder */
730 hr
= IFileOpenDialog_SetDefaultFolder(pfod
, NULL
);
731 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
732 hr
= IFileSaveDialog_SetDefaultFolder(pfsd
, NULL
);
733 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
735 hr
= IFileOpenDialog_SetDefaultFolder(pfod
, psidesktop
);
736 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
737 hr
= IFileSaveDialog_SetDefaultFolder(pfsd
, psidesktop
);
738 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
742 /* Crashes under Windows 7 */
743 IFileOpenDialog_SetDefaultFolder(pfod
, (void*)0x1234);
744 IFileSaveDialog_SetDefaultFolder(pfsd
, (void*)0x1234);
747 /* GetFolder / SetFolder */
748 hr
= IFileOpenDialog_GetFolder(pfod
, NULL
);
749 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
751 hr
= IFileOpenDialog_GetFolder(pfod
, &psi_original
);
752 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
755 hr
= IFileOpenDialog_SetFolder(pfod
, psidesktop
);
756 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
757 hr
= IFileOpenDialog_SetFolder(pfod
, psi_original
);
758 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
759 IShellItem_Release(psi_original
);
762 hr
= IFileSaveDialog_GetFolder(pfsd
, &psi_original
);
763 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
766 hr
= IFileSaveDialog_SetFolder(pfsd
, psidesktop
);
767 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
768 hr
= IFileSaveDialog_SetFolder(pfsd
, psi_original
);
769 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
770 IShellItem_Release(psi_original
);
776 /* Crashes under Windows 7 */
777 IFileOpenDialog_AddPlace(pfod
, NULL
, 0);
778 IFileSaveDialog_AddPlace(pfsd
, NULL
, 0);
781 hr
= IFileOpenDialog_AddPlace(pfod
, psidesktop
, FDAP_TOP
+ 1);
782 todo_wine
ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
783 hr
= IFileOpenDialog_AddPlace(pfod
, psidesktop
, FDAP_BOTTOM
);
784 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
785 hr
= IFileOpenDialog_AddPlace(pfod
, psidesktop
, FDAP_TOP
);
786 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
788 hr
= IFileSaveDialog_AddPlace(pfsd
, psidesktop
, FDAP_TOP
+ 1);
789 todo_wine
ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
790 hr
= IFileSaveDialog_AddPlace(pfsd
, psidesktop
, FDAP_BOTTOM
);
791 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
792 hr
= IFileSaveDialog_AddPlace(pfsd
, psidesktop
, FDAP_TOP
);
793 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
796 hr
= IFileOpenDialog_SetFileName(pfod
, NULL
);
797 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
798 hr
= IFileOpenDialog_SetFileName(pfod
, null
);
799 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
800 hr
= IFileOpenDialog_SetFileName(pfod
, txt
);
801 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
802 hr
= IFileOpenDialog_GetFileName(pfod
, &filename
);
803 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
804 ok(!lstrcmpW(filename
, txt
), "Strings do not match.\n");
805 CoTaskMemFree(filename
);
807 hr
= IFileSaveDialog_SetFileName(pfsd
, NULL
);
808 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
809 hr
= IFileSaveDialog_SetFileName(pfsd
, null
);
810 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
811 hr
= IFileSaveDialog_SetFileName(pfsd
, txt
);
812 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
813 hr
= IFileSaveDialog_GetFileName(pfsd
, &filename
);
814 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
815 ok(!lstrcmpW(filename
, txt
), "Strings do not match.\n");
816 CoTaskMemFree(filename
);
818 /* SetFileNameLabel */
819 hr
= IFileOpenDialog_SetFileNameLabel(pfod
, NULL
);
820 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
821 hr
= IFileOpenDialog_SetFileNameLabel(pfod
, null
);
822 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
823 hr
= IFileOpenDialog_SetFileNameLabel(pfod
, txt
);
824 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
826 hr
= IFileSaveDialog_SetFileNameLabel(pfsd
, NULL
);
827 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
828 hr
= IFileSaveDialog_SetFileNameLabel(pfsd
, null
);
829 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
830 hr
= IFileSaveDialog_SetFileNameLabel(pfsd
, txt
);
831 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
834 hr
= IFileOpenDialog_Close(pfod
, S_FALSE
);
835 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
836 hr
= IFileSaveDialog_Close(pfsd
, S_FALSE
);
837 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
839 /* SetOkButtonLabel */
840 hr
= IFileOpenDialog_SetOkButtonLabel(pfod
, NULL
);
841 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
842 hr
= IFileOpenDialog_SetOkButtonLabel(pfod
, null
);
843 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
844 hr
= IFileOpenDialog_SetOkButtonLabel(pfod
, txt
);
845 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
846 hr
= IFileSaveDialog_SetOkButtonLabel(pfsd
, NULL
);
847 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
848 hr
= IFileSaveDialog_SetOkButtonLabel(pfsd
, null
);
849 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
850 hr
= IFileSaveDialog_SetOkButtonLabel(pfsd
, txt
);
851 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
854 hr
= IFileOpenDialog_SetTitle(pfod
, NULL
);
855 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
856 hr
= IFileOpenDialog_SetTitle(pfod
, null
);
857 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
858 hr
= IFileOpenDialog_SetTitle(pfod
, txt
);
859 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
860 hr
= IFileSaveDialog_SetTitle(pfsd
, NULL
);
861 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
862 hr
= IFileSaveDialog_SetTitle(pfsd
, null
);
863 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
864 hr
= IFileSaveDialog_SetTitle(pfsd
, txt
);
865 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
867 /** IFileOpenDialog specific **/
872 /* Crashes under Windows 7 */
873 IFileOpenDialog_GetResults(pfod
, NULL
);
875 psia
= (void*)0xdeadbeef;
876 hr
= IFileOpenDialog_GetResults(pfod
, &psia
);
877 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
878 ok(psia
== NULL
, "got %p.\n", psia
);
880 /* GetSelectedItems */
883 /* Crashes under W2K8 */
884 hr
= IFileOpenDialog_GetSelectedItems(pfod
, NULL
);
885 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
886 psia
= (void*)0xdeadbeef;
887 hr
= IFileOpenDialog_GetSelectedItems(pfod
, &psia
);
888 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
889 ok(psia
== (void*)0xdeadbeef, "got %p.\n", psia
);
892 /** IFileSaveDialog specific **/
894 /* ApplyProperties */
897 /* Crashes under windows 7 */
898 IFileSaveDialog_ApplyProperties(pfsd
, NULL
, NULL
, NULL
, NULL
);
899 IFileSaveDialog_ApplyProperties(pfsd
, psidesktop
, NULL
, NULL
, NULL
);
903 hr
= IFileSaveDialog_GetProperties(pfsd
, NULL
);
904 todo_wine
ok(hr
== E_UNEXPECTED
, "got 0x%08x\n", hr
);
905 pps
= (void*)0xdeadbeef;
906 hr
= IFileSaveDialog_GetProperties(pfsd
, &pps
);
907 todo_wine
ok(hr
== E_UNEXPECTED
, "got 0x%08x\n", hr
);
908 ok(pps
== (void*)0xdeadbeef, "got %p\n", pps
);
913 /* Crashes under W2K8 */
914 hr
= IFileSaveDialog_SetProperties(pfsd
, NULL
);
915 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
918 /* SetCollectedProperties */
921 hr
= IFileSaveDialog_SetCollectedProperties(pfsd
, NULL
, TRUE
);
922 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
923 hr
= IFileSaveDialog_SetCollectedProperties(pfsd
, NULL
, FALSE
);
924 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
930 hr
= IFileSaveDialog_SetSaveAsItem(pfsd
, NULL
);
931 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
932 hr
= IFileSaveDialog_SetSaveAsItem(pfsd
, psidesktop
);
933 ok(hr
== MK_E_NOOBJECT
, "got 0x%08x\n", hr
);
938 hr
= IFileOpenDialog_QueryInterface(pfod
, &IID_IFileDialog2
, (void**)&pfd2
);
939 ok((hr
== S_OK
) || broken(hr
== E_NOINTERFACE
), "got 0x%08x\n", hr
);
942 /* SetCancelButtonLabel */
943 hr
= IFileDialog2_SetOkButtonLabel(pfd2
, NULL
);
944 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
945 hr
= IFileDialog2_SetOkButtonLabel(pfd2
, null
);
946 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
947 hr
= IFileDialog2_SetOkButtonLabel(pfd2
, txt
);
948 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
950 /* SetNavigationRoot */
953 hr
= IFileDialog2_SetNavigationRoot(pfd2
, NULL
);
954 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
955 hr
= IFileDialog2_SetNavigationRoot(pfd2
, psidesktop
);
956 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
959 IFileDialog2_Release(pfd2
);
962 hr
= IFileSaveDialog_QueryInterface(pfsd
, &IID_IFileDialog2
, (void**)&pfd2
);
963 ok((hr
== S_OK
) || broken(hr
== E_NOINTERFACE
), "got 0x%08x\n", hr
);
966 /* SetCancelButtonLabel */
967 hr
= IFileDialog2_SetOkButtonLabel(pfd2
, NULL
);
968 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
969 hr
= IFileDialog2_SetOkButtonLabel(pfd2
, null
);
970 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
971 hr
= IFileDialog2_SetOkButtonLabel(pfd2
, txt
);
972 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
974 /* SetNavigationRoot */
977 hr
= IFileDialog2_SetNavigationRoot(pfd2
, NULL
);
978 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
979 hr
= IFileDialog2_SetNavigationRoot(pfd2
, psidesktop
);
980 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
983 IFileDialog2_Release(pfd2
);
987 IShellItem_Release(psidesktop
);
988 ref
= IFileOpenDialog_Release(pfod
);
989 ok(!ref
, "Got refcount %d, should have been released.\n", ref
);
990 ref
= IFileSaveDialog_Release(pfsd
);
991 ok(!ref
, "Got refcount %d, should have been released.\n", ref
);
994 static void ensure_zero_events_(const char *file
, int line
, IFileDialogEventsImpl
*impl
)
996 ok_(file
, line
)(!impl
->OnFileOk
, "OnFileOk: %d\n", impl
->OnFileOk
);
997 ok_(file
, line
)(!impl
->OnFolderChanging
, "OnFolderChanging: %d\n", impl
->OnFolderChanging
);
998 ok_(file
, line
)(!impl
->OnFolderChange
, "OnFolderChange: %d\n", impl
->OnFolderChange
);
999 ok_(file
, line
)(!impl
->OnSelectionChange
, "OnSelectionChange: %d\n", impl
->OnSelectionChange
);
1000 ok_(file
, line
)(!impl
->OnShareViolation
, "OnShareViolation: %d\n", impl
->OnShareViolation
);
1001 ok_(file
, line
)(!impl
->OnTypeChange
, "OnTypeChange: %d\n", impl
->OnTypeChange
);
1002 ok_(file
, line
)(!impl
->OnOverwrite
, "OnOverwrite: %d\n", impl
->OnOverwrite
);
1003 impl
->OnFileOk
= impl
->OnFolderChanging
= impl
->OnFolderChange
= 0;
1004 impl
->OnSelectionChange
= impl
->OnShareViolation
= impl
->OnTypeChange
= 0;
1005 impl
->OnOverwrite
= 0;
1007 #define ensure_zero_events(impl) ensure_zero_events_(__FILE__, __LINE__, impl)
1009 static void test_advise_helper(IFileDialog
*pfd
)
1011 IFileDialogEventsImpl
*pfdeimpl
;
1012 IFileDialogEvents
*pfde
;
1017 pfde
= IFileDialogEvents_Constructor();
1018 pfdeimpl
= impl_from_IFileDialogEvents(pfde
);
1020 hr
= IFileDialog_Advise(pfd
, NULL
, NULL
);
1021 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1022 hr
= IFileDialog_Advise(pfd
, pfde
, NULL
);
1023 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1024 hr
= IFileDialog_Advise(pfd
, NULL
, &cookie
[0]);
1025 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1026 ok(pfdeimpl
->ref
== 1, "got ref %d\n", pfdeimpl
->ref
);
1027 ensure_zero_events(pfdeimpl
);
1029 hr
= IFileDialog_Unadvise(pfd
, 0);
1030 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1031 for(i
= 0; i
< 10; i
++) {
1032 hr
= IFileDialog_Advise(pfd
, pfde
, &cookie
[i
]);
1033 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1034 ok(cookie
[i
] == i
+1, "Got cookie: %d\n", cookie
[i
]);
1036 ok(pfdeimpl
->ref
== 10+1, "got ref %d\n", pfdeimpl
->ref
);
1037 ensure_zero_events(pfdeimpl
);
1039 for(i
= 3; i
< 7; i
++) {
1040 hr
= IFileDialog_Unadvise(pfd
, cookie
[i
]);
1041 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1043 ok(pfdeimpl
->ref
== 6+1, "got ref %d\n", pfdeimpl
->ref
);
1044 ensure_zero_events(pfdeimpl
);
1046 for(i
= 0; i
< 3; i
++) {
1047 hr
= IFileDialog_Unadvise(pfd
, cookie
[i
]);
1048 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1050 ok(pfdeimpl
->ref
== 3+1, "got ref %d\n", pfdeimpl
->ref
);
1051 ensure_zero_events(pfdeimpl
);
1053 for(i
= 7; i
< 10; i
++) {
1054 hr
= IFileDialog_Unadvise(pfd
, cookie
[i
]);
1055 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1057 ok(pfdeimpl
->ref
== 1, "got ref %d\n", pfdeimpl
->ref
);
1058 ensure_zero_events(pfdeimpl
);
1060 hr
= IFileDialog_Unadvise(pfd
, cookie
[9]+1);
1061 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1062 ok(pfdeimpl
->ref
== 1, "got ref %d\n", pfdeimpl
->ref
);
1063 ensure_zero_events(pfdeimpl
);
1065 hr
= IFileDialog_Advise(pfd
, pfde
, &cookie
[0]);
1066 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1067 todo_wine
ok(cookie
[0] == 1, "got cookie: %d\n", cookie
[0]);
1068 ok(pfdeimpl
->ref
== 1+1, "got ref %d\n", pfdeimpl
->ref
);
1069 ensure_zero_events(pfdeimpl
);
1071 hr
= IFileDialog_Unadvise(pfd
, cookie
[0]);
1075 /* Unadvising already unadvised cookies crashes on
1077 IFileDialog_Unadvise(pfd
, cookie
[0]);
1081 IFileDialogEvents_Release(pfde
);
1084 static void test_advise(void)
1090 trace("Testing FileOpenDialog (advise)\n");
1091 hr
= CoCreateInstance(&CLSID_FileOpenDialog
, NULL
, CLSCTX_INPROC_SERVER
,
1092 &IID_IFileDialog
, (void**)&pfd
);
1093 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1094 test_advise_helper(pfd
);
1095 ref
= IFileDialog_Release(pfd
);
1096 ok(!ref
, "Got refcount %d, should have been released.\n", ref
);
1098 trace("Testing FileSaveDialog (advise)\n");
1099 hr
= CoCreateInstance(&CLSID_FileSaveDialog
, NULL
, CLSCTX_INPROC_SERVER
,
1100 &IID_IFileDialog
, (void**)&pfd
);
1101 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1102 test_advise_helper(pfd
);
1103 ref
= IFileDialog_Release(pfd
);
1104 ok(!ref
, "Got refcount %d, should have been released.\n", ref
);
1107 static void filedialog_change_filetype(IFileDialog
*pfd
, HWND dlg_hwnd
)
1110 const WCHAR filetype1
[] = {'f','n','a','m','e','1',0};
1111 const WCHAR filetype1_broken
[] = {'f','n','a','m','e','1',' ', '(','*','.','t','x','t',')',0};
1113 cb_filetype
= find_window(dlg_hwnd
, NULL
, filetype1
);
1114 ok(cb_filetype
!= NULL
|| broken(cb_filetype
== NULL
), "Could not find combobox on first attempt\n");
1118 /* Not sure when this happens. Some specific version?
1119 * Seen on 32-bit English Vista */
1120 trace("Didn't find combobox on first attempt, trying broken string..\n");
1121 cb_filetype
= find_window(dlg_hwnd
, NULL
, filetype1_broken
);
1122 ok(broken(cb_filetype
!= NULL
), "Failed to find combobox on second attempt\n");
1127 /* Making the combobox send a CBN_SELCHANGE */
1128 SendMessageW( cb_filetype
, CB_SHOWDROPDOWN
, 1, 0 );
1129 SendMessageW( cb_filetype
, CB_SETCURSEL
, 1, 0 );
1130 SendMessageW( cb_filetype
, WM_LBUTTONDOWN
, 0, -1 );
1131 SendMessageW( cb_filetype
, WM_LBUTTONUP
, 0, -1 );
1134 static void test_events(void)
1137 IFileDialogEventsImpl
*pfdeimpl
;
1138 IFileDialogEvents
*pfde
;
1142 const WCHAR fname1
[] = {'f','n','a','m','e','1', 0};
1143 const WCHAR fspec1
[] = {'*','.','t','x','t',0};
1144 const WCHAR fname2
[] = {'f','n','a','m','e','2', 0};
1145 const WCHAR fspec2
[] = {'*','.','e','x','e',0};
1146 COMDLG_FILTERSPEC filterspec
[3] = {{fname1
, fspec1
}, {fname2
, fspec2
}};
1150 * 1. Show the dialog with no filetypes added
1152 hr
= CoCreateInstance(&CLSID_FileOpenDialog
, NULL
, CLSCTX_INPROC_SERVER
,
1153 &IID_IFileDialog
, (void**)&pfd
);
1154 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1156 pfde
= IFileDialogEvents_Constructor();
1157 pfdeimpl
= impl_from_IFileDialogEvents(pfde
);
1158 pfdeimpl
->events_test
= IFDEVENT_TEST2
;
1160 hr
= IFileDialog_Advise(pfd
, pfde
, &cookie
);
1161 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1163 hr
= IFileDialog_Show(pfd
, NULL
);
1164 ok(hr
== HRESULT_FROM_WIN32(ERROR_CANCELLED
), "got 0x%08x.\n", hr
);
1166 ok(pfdeimpl
->OnFolderChanging
== 1, "Got %d\n", pfdeimpl
->OnFolderChanging
);
1167 pfdeimpl
->OnFolderChanging
= 0;
1168 ok(pfdeimpl
->OnFolderChange
== 1, "Got %d\n", pfdeimpl
->OnFolderChange
);
1169 pfdeimpl
->OnFolderChange
= 0;
1170 /* pfdeimpl->OnSelectionChange too unreliable to test. Can be 0, 1 or even 2. */
1171 pfdeimpl
->OnSelectionChange
= 0;
1172 ok(pfdeimpl
->OnTypeChange
== 0, "Got %d\n", pfdeimpl
->OnTypeChange
);
1173 pfdeimpl
->OnTypeChange
= 0;
1175 ensure_zero_events(pfdeimpl
);
1177 hr
= IFileDialog_Unadvise(pfd
, cookie
);
1178 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1180 IFileDialogEvents_Release(pfde
);
1181 ref
= IFileDialog_Release(pfd
);
1182 ok(!ref
|| broken(ref
/* win2008_64 (intermittently) */), "Got %d\n", ref
);
1186 * 2. Show the dialog with filetypes added
1188 hr
= CoCreateInstance(&CLSID_FileOpenDialog
, NULL
, CLSCTX_INPROC_SERVER
,
1189 &IID_IFileDialog
, (void**)&pfd
);
1190 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1192 pfde
= IFileDialogEvents_Constructor();
1193 pfdeimpl
= impl_from_IFileDialogEvents(pfde
);
1194 pfdeimpl
->events_test
= IFDEVENT_TEST2
;
1196 hr
= IFileDialog_Advise(pfd
, pfde
, &cookie
);
1197 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1199 hr
= IFileDialog_SetFileTypes(pfd
, 2, filterspec
);
1200 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1202 ensure_zero_events(pfdeimpl
);
1204 hr
= IFileDialog_Show(pfd
, NULL
);
1205 ok(hr
== HRESULT_FROM_WIN32(ERROR_CANCELLED
), "got 0x%08x.\n", hr
);
1207 ok(pfdeimpl
->OnFolderChanging
== 1, "Got %d\n", pfdeimpl
->OnFolderChanging
);
1208 pfdeimpl
->OnFolderChanging
= 0;
1209 ok(pfdeimpl
->OnFolderChange
== 1, "Got %d\n", pfdeimpl
->OnFolderChange
);
1210 pfdeimpl
->OnFolderChange
= 0;
1211 /* pfdeimpl->OnSelectionChange too unreliable to test. Can be 0, 1 or even 2. */
1212 pfdeimpl
->OnSelectionChange
= 0;
1213 /* Called once just by showing the dialog */
1214 ok(pfdeimpl
->OnTypeChange
== 1, "Got %d\n", pfdeimpl
->OnTypeChange
);
1215 pfdeimpl
->OnTypeChange
= 0;
1217 ensure_zero_events(pfdeimpl
);
1219 hr
= IFileDialog_Unadvise(pfd
, cookie
);
1220 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1222 IFileDialogEvents_Release(pfde
);
1223 ref
= IFileDialog_Release(pfd
);
1224 ok(!ref
|| broken(ref
/* win2008_64 (intermittently) */), "Got %d\n", ref
);
1228 * 3. Show the dialog with filetypes added and simulate manual change of filetype
1230 hr
= CoCreateInstance(&CLSID_FileOpenDialog
, NULL
, CLSCTX_INPROC_SERVER
,
1231 &IID_IFileDialog
, (void**)&pfd
);
1232 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1234 pfde
= IFileDialogEvents_Constructor();
1235 pfdeimpl
= impl_from_IFileDialogEvents(pfde
);
1236 pfdeimpl
->events_test
= IFDEVENT_TEST3
;
1238 hr
= IFileDialog_Advise(pfd
, pfde
, &cookie
);
1239 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1241 hr
= IFileDialog_SetFileTypes(pfd
, 2, filterspec
);
1242 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1244 ensure_zero_events(pfdeimpl
);
1246 hr
= IFileDialog_Show(pfd
, NULL
);
1247 ok(hr
== HRESULT_FROM_WIN32(ERROR_CANCELLED
), "got 0x%08x.\n", hr
);
1249 ok(pfdeimpl
->OnFolderChanging
== 1, "Got %d\n", pfdeimpl
->OnFolderChanging
);
1250 pfdeimpl
->OnFolderChanging
= 0;
1251 ok(pfdeimpl
->OnFolderChange
== 1, "Got %d\n", pfdeimpl
->OnFolderChange
);
1252 pfdeimpl
->OnFolderChange
= 0;
1253 /* pfdeimpl->OnSelectionChange too unreliable to test. Can be 0, 1 or even 2. */
1254 pfdeimpl
->OnSelectionChange
= 0;
1255 /* Called once by showing the dialog and once again when changing the filetype */
1256 todo_wine
ok(pfdeimpl
->OnTypeChange
== 2, "Got %d\n", pfdeimpl
->OnTypeChange
);
1257 pfdeimpl
->OnTypeChange
= 0;
1259 ensure_zero_events(pfdeimpl
);
1261 hr
= IFileDialog_Unadvise(pfd
, cookie
);
1262 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1264 IFileDialogEvents_Release(pfde
);
1265 ref
= IFileDialog_Release(pfd
);
1266 ok(!ref
|| broken(ref
/* win2008_64 (intermittently) */), "Got %d\n", ref
);
1269 static void touch_file(LPCWSTR filename
)
1272 file
= CreateFileW(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1273 ok(file
!= INVALID_HANDLE_VALUE
, "Failed to create file.\n");
1277 static void test_filename_savedlg_(LPCWSTR set_filename
, LPCWSTR defext
,
1278 const COMDLG_FILTERSPEC
*filterspec
, UINT fs_count
,
1279 LPCWSTR exp_filename
, const char *file
, int line
)
1281 IFileSaveDialog
*pfsd
;
1282 IFileDialogEventsImpl
*pfdeimpl
;
1283 IFileDialogEvents
*pfde
;
1290 hr
= CoCreateInstance(&CLSID_FileSaveDialog
, NULL
, CLSCTX_INPROC_SERVER
,
1291 &IID_IFileSaveDialog
, (void**)&pfsd
);
1292 ok_(file
,line
)(hr
== S_OK
, "Got 0x%08x\n", hr
);
1296 hr
= IFileSaveDialog_SetFileTypes(pfsd
, fs_count
, filterspec
);
1297 ok_(file
,line
)(hr
== S_OK
, "SetFileTypes failed: Got 0x%08x\n", hr
);
1302 hr
= IFileSaveDialog_SetDefaultExtension(pfsd
, defext
);
1303 ok_(file
,line
)(hr
== S_OK
, "SetDefaultExtensions failed: Got 0x%08x\n", hr
);
1306 pfde
= IFileDialogEvents_Constructor();
1307 pfdeimpl
= impl_from_IFileDialogEvents(pfde
);
1308 pfdeimpl
->set_filename
= set_filename
;
1309 hr
= IFileSaveDialog_Advise(pfsd
, pfde
, &cookie
);
1310 ok_(file
,line
)(hr
== S_OK
, "Advise failed: Got 0x%08x\n", hr
);
1312 hr
= IFileSaveDialog_Show(pfsd
, NULL
);
1313 ok_(file
,line
)(hr
== S_OK
, "Show failed: Got 0x%08x\n", hr
);
1315 hr
= IFileSaveDialog_GetFileName(pfsd
, &filename
);
1316 ok_(file
,line
)(hr
== S_OK
, "GetFileName failed: Got 0x%08x\n", hr
);
1317 ok_(file
,line
)(!lstrcmpW(filename
, set_filename
), "Got %s\n", wine_dbgstr_w(filename
));
1318 CoTaskMemFree(filename
);
1320 hr
= IFileSaveDialog_GetResult(pfsd
, &psi
);
1321 ok_(file
,line
)(hr
== S_OK
, "GetResult failed: Got 0x%08x\n", hr
);
1323 hr
= IShellItem_GetDisplayName(psi
, SIGDN_PARENTRELATIVEPARSING
, &filename
);
1324 ok_(file
,line
)(hr
== S_OK
, "GetDisplayName failed: Got 0x%08x\n", hr
);
1325 ok_(file
,line
)(!lstrcmpW(filename
, exp_filename
), "(GetDisplayName) Got %s\n", wine_dbgstr_w(filename
));
1326 CoTaskMemFree(filename
);
1327 IShellItem_Release(psi
);
1329 hr
= IFileSaveDialog_Unadvise(pfsd
, cookie
);
1330 ok_(file
,line
)(hr
== S_OK
, "Unadvise failed: Got 0x%08x\n", hr
);
1332 ref
= IFileSaveDialog_Release(pfsd
);
1333 ok_(file
,line
)(!ref
, "Got refcount %d, should have been released.\n", ref
);
1335 IFileDialogEvents_Release(pfde
);
1337 #define test_filename_savedlg(set_filename, defext, filterspec, fs_count, exp_filename) \
1338 test_filename_savedlg_(set_filename, defext, filterspec, fs_count, exp_filename, __FILE__, __LINE__)
1340 static void test_filename_opendlg_(LPCWSTR set_filename
, IShellItem
*psi_current
, LPCWSTR defext
,
1341 const COMDLG_FILTERSPEC
*filterspec
, UINT fs_count
,
1342 LPCWSTR exp_filename
, const char *file
, int line
)
1344 IFileOpenDialog
*pfod
;
1345 IFileDialogEventsImpl
*pfdeimpl
;
1346 IFileDialogEvents
*pfde
;
1349 IShellItemArray
*psia
;
1354 hr
= CoCreateInstance(&CLSID_FileOpenDialog
, NULL
, CLSCTX_INPROC_SERVER
,
1355 &IID_IFileOpenDialog
, (void**)&pfod
);
1356 ok_(file
,line
)(hr
== S_OK
, "CoCreateInstance failed: Got 0x%08x\n", hr
);
1360 hr
= IFileOpenDialog_SetDefaultExtension(pfod
, defext
);
1361 ok_(file
,line
)(hr
== S_OK
, "SetDefaultExtensions failed: Got 0x%08x\n", hr
);
1366 hr
= IFileOpenDialog_SetFileTypes(pfod
, 2, filterspec
);
1367 ok_(file
,line
)(hr
== S_OK
, "SetFileTypes failed: Got 0x%08x\n", hr
);
1370 hr
= IFileOpenDialog_SetFolder(pfod
, psi_current
);
1371 ok_(file
,line
)(hr
== S_OK
, "SetFolder failed: Got 0x%08x\n", hr
);
1373 pfde
= IFileDialogEvents_Constructor();
1374 pfdeimpl
= impl_from_IFileDialogEvents(pfde
);
1375 pfdeimpl
->set_filename
= set_filename
;
1376 pfdeimpl
->set_filename_tried
= FALSE
;
1377 hr
= IFileOpenDialog_Advise(pfod
, pfde
, &cookie
);
1378 ok_(file
,line
)(hr
== S_OK
, "Advise failed: Got 0x%08x\n", hr
);
1380 hr
= IFileOpenDialog_Show(pfod
, NULL
);
1381 ok_(file
,line
)(hr
== S_OK
|| (!exp_filename
&& hr
== HRESULT_FROM_WIN32(ERROR_CANCELLED
)),
1382 "Show failed: Got 0x%08x\n", hr
);
1385 hr
= IFileOpenDialog_GetResult(pfod
, &psi
);
1386 ok_(file
,line
)(hr
== S_OK
, "GetResult failed: Got 0x%08x\n", hr
);
1388 hr
= IShellItem_GetDisplayName(psi
, SIGDN_PARENTRELATIVEPARSING
, &filename
);
1389 ok_(file
,line
)(hr
== S_OK
, "GetDisplayName(Result) failed: Got 0x%08x\n", hr
);
1390 ok_(file
,line
)(!lstrcmpW(filename
, exp_filename
), "(GetResult) Got %s\n", wine_dbgstr_w(filename
));
1391 CoTaskMemFree(filename
);
1392 IShellItem_Release(psi
);
1394 hr
= IFileOpenDialog_GetResults(pfod
, &psia
);
1395 ok_(file
,line
)(hr
== S_OK
, "GetResults failed: Got 0x%08x\n", hr
);
1396 hr
= IShellItemArray_GetItemAt(psia
, 0, &psi
);
1397 ok_(file
,line
)(hr
== S_OK
, "GetItemAt failed: Got 0x%08x\n", hr
);
1399 hr
= IShellItem_GetDisplayName(psi
, SIGDN_PARENTRELATIVEPARSING
, &filename
);
1400 ok_(file
,line
)(hr
== S_OK
, "GetDisplayName(Results) failed: Got 0x%08x\n", hr
);
1401 ok_(file
,line
)(!lstrcmpW(filename
, exp_filename
), "(GetResults) Got %s\n", wine_dbgstr_w(filename
));
1402 CoTaskMemFree(filename
);
1404 IShellItem_Release(psi
);
1405 IShellItemArray_Release(psia
);
1409 hr
= IFileOpenDialog_GetResult(pfod
, &psi
);
1410 ok_(file
,line
)(hr
== E_UNEXPECTED
, "GetResult: Got 0x%08x\n", hr
);
1412 hr
= IFileOpenDialog_GetResults(pfod
, &psia
);
1413 ok_(file
,line
)(hr
== E_FAIL
, "GetResults: Got 0x%08x\n", hr
);
1416 hr
= IFileOpenDialog_GetFileName(pfod
, &filename
);
1417 ok_(file
,line
)(hr
== S_OK
, "GetFileName failed: Got 0x%08x\n", hr
);
1418 ok_(file
,line
)(!lstrcmpW(filename
, set_filename
), "(GetFileName) Got %s\n", wine_dbgstr_w(filename
));
1419 CoTaskMemFree(filename
);
1422 hr
= IFileOpenDialog_Unadvise(pfod
, cookie
);
1423 ok_(file
,line
)(hr
== S_OK
, "Unadvise failed: Got 0x%08x\n", hr
);
1425 ref
= IFileOpenDialog_Release(pfod
);
1426 ok_(file
,line
)(!ref
, "Got refcount %d, should have been released.\n", ref
);
1428 IFileDialogEvents_Release(pfde
);
1430 #define test_filename_opendlg(set_filename, psi, defext, filterspec, fs_count, exp_filename) \
1431 test_filename_opendlg_(set_filename, psi, defext, filterspec, fs_count, exp_filename, __FILE__, __LINE__)
1433 static void test_filename(void)
1435 IShellItem
*psi_current
;
1437 WCHAR buf
[MAX_PATH
];
1439 static const WCHAR filename_noextW
[] = {'w','i','n','e','t','e','s','t',0};
1440 static const WCHAR filename_dotextW
[] = {'w','i','n','e','t','e','s','t','.',0};
1441 static const WCHAR filename_dotanddefW
[] = {'w','i','n','e','t','e','s','t','.','.','w','t','e',0};
1442 static const WCHAR filename_defextW
[] = {'w','i','n','e','t','e','s','t','.','w','t','e',0};
1443 static const WCHAR filename_ext1W
[] = {'w','i','n','e','t','e','s','t','.','w','t','1',0};
1444 static const WCHAR filename_ext2W
[] = {'w','i','n','e','t','e','s','t','.','w','t','2',0};
1445 static const WCHAR filename_ext1anddefW
[] =
1446 {'w','i','n','e','t','e','s','t','.','w','t','1','.','w','t','e',0};
1447 static const WCHAR defextW
[] = {'w','t','e',0};
1448 static const WCHAR desc1
[] = {'d','e','s','c','r','i','p','t','i','o','n','1',0};
1449 static const WCHAR desc2
[] = {'d','e','s','c','r','i','p','t','i','o','n','2',0};
1450 static const WCHAR descdef
[] = {'d','e','f','a','u','l','t',' ','d','e','s','c',0};
1451 static const WCHAR ext1
[] = {'*','.','w','t','1',0};
1452 static const WCHAR ext2
[] = {'*','.','w','t','2',0};
1453 static const WCHAR extdef
[] = {'*','.','w','t','e',0};
1454 static const WCHAR complexext
[] = {'*','.','w','t','2',';','*','.','w','t','1',0};
1456 static const COMDLG_FILTERSPEC filterspec
[] = {
1457 { desc1
, ext1
}, { desc2
, ext2
}, { descdef
, extdef
}
1459 static const COMDLG_FILTERSPEC filterspec2
[] = {
1460 { desc1
, complexext
}
1464 test_filename_savedlg(filename_noextW
, NULL
, NULL
, 0, filename_noextW
);
1465 /* Default extension */
1466 test_filename_savedlg(filename_noextW
, defextW
, NULL
, 0, filename_defextW
);
1467 /* Default extension on filename ending with a . */
1468 test_filename_savedlg(filename_dotextW
, defextW
, NULL
, 0, filename_dotanddefW
);
1469 /* Default extension on filename with default extension */
1470 test_filename_savedlg(filename_defextW
, defextW
, NULL
, 0, filename_defextW
);
1471 /* Default extension on filename with another extension */
1472 test_filename_savedlg(filename_ext1W
, defextW
, NULL
, 0, filename_ext1anddefW
);
1473 /* Default extension, filterspec without default extension */
1474 test_filename_savedlg(filename_noextW
, defextW
, filterspec
, 2, filename_ext1W
);
1475 /* Default extension, filterspec with default extension */
1476 test_filename_savedlg(filename_noextW
, defextW
, filterspec
, 3, filename_ext1W
);
1477 /* Default extension, filterspec with "complex" extension */
1478 test_filename_savedlg(filename_noextW
, defextW
, filterspec2
, 1, filename_ext2W
);
1480 GetCurrentDirectoryW(MAX_PATH
, buf
);
1481 ok(!!pSHCreateItemFromParsingName
, "SHCreateItemFromParsingName is missing.\n");
1482 hr
= pSHCreateItemFromParsingName(buf
, NULL
, &IID_IShellItem
, (void**)&psi_current
);
1483 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
1485 touch_file(filename_noextW
);
1486 touch_file(filename_defextW
);
1487 touch_file(filename_ext2W
);
1489 /* IFileOpenDialog, default extension */
1490 test_filename_opendlg(filename_noextW
, psi_current
, defextW
, NULL
, 0, filename_noextW
);
1491 /* IFileOpenDialog, default extension and filterspec */
1492 test_filename_opendlg(filename_noextW
, psi_current
, defextW
, filterspec
, 2, filename_noextW
);
1494 DeleteFileW(filename_noextW
);
1495 /* IFileOpenDialog, default extension, noextW deleted */
1496 test_filename_opendlg(filename_noextW
, psi_current
, defextW
, NULL
, 0, filename_defextW
);
1497 if(0) /* Interactive */
1499 /* IFileOpenDialog, filterspec, no default extension, noextW deleted */
1500 test_filename_opendlg(filename_noextW
, psi_current
, NULL
, filterspec
, 2, NULL
);
1503 IShellItem_Release(psi_current
);
1504 DeleteFileW(filename_defextW
);
1505 DeleteFileW(filename_ext2W
);
1508 static const WCHAR label
[] = {'l','a','b','e','l',0};
1509 static const WCHAR label2
[] = {'t','e','s','t',0};
1510 static const WCHAR menuW
[] = {'m','e','n','u','_','i','t','e','m',0};
1511 static const WCHAR pushbutton1W
[] = {'p','u','s','h','b','u','t','t','o','n','_','i','t','e','m',0};
1512 static const WCHAR pushbutton2W
[] = {'p','u','s','h','b','u','t','t','o','n','2','_','i','t','e','m',0};
1513 static const WCHAR comboboxitem1W
[] = {'c','o','m','b','o','b','o','x','1','_','i','t','e','m',0};
1514 static const WCHAR comboboxitem2W
[] = {'c','o','m','b','o','b','o','x','2','_','i','t','e','m',0};
1515 static const WCHAR radiobutton1W
[] = {'r','a','d','i','o','b','u','t','t','o','n','1','_','i','t','e','m',0};
1516 static const WCHAR radiobutton2W
[] = {'r','a','d','i','o','b','u','t','t','o','n','2','_','i','t','e','m',0};
1517 static const WCHAR checkbutton1W
[] = {'c','h','e','c','k','b','u','t','t','o','n','1','_','i','t','e','m',0};
1518 static const WCHAR checkbutton2W
[] = {'c','h','e','c','k','b','u','t','t','o','n','2','_','i','t','e','m',0};
1519 static const WCHAR editbox1W
[] = {'e','d','i','t','b','o','x','W','1','_','i','t','e','m',0};
1520 static const WCHAR editbox2W
[] = {'e','d','i','t','b','o','x','W','2','_','i','t','e','m',0};
1521 static const WCHAR textW
[] = {'t','e','x','t','_','i','t','e','m',0};
1522 static const WCHAR text2W
[] = {'t','e','x','t','2','_','i','t','e','m',0};
1523 static const WCHAR separatorW
[] = {'s','e','p','a','r','a','t','o','r','_','i','t','e','m',0};
1524 static const WCHAR visualgroup1W
[] = {'v','i','s','u','a','l','g','r','o','u','p','1',0};
1525 static const WCHAR visualgroup2W
[] = {'v','i','s','u','a','l','g','r','o','u','p','2',0};
1527 static const WCHAR floatnotifysinkW
[] = {'F','l','o','a','t','N','o','t','i','f','y','S','i','n','k',0};
1528 static const WCHAR RadioButtonListW
[] = {'R','a','d','i','o','B','u','t','t','o','n','L','i','s','t',0};
1530 static void test_customize_onfolderchange(IFileDialog
*pfd
)
1532 HWND dlg_hwnd
, item
, item_parent
;
1538 dlg_hwnd
= get_hwnd_from_ifiledialog(pfd
);
1539 ok(dlg_hwnd
!= NULL
, "Got NULL.\n");
1541 item
= find_window(dlg_hwnd
, NULL
, checkbutton2W
);
1542 ok(item
!= NULL
, "Failed to find item.\n");
1543 item_parent
= GetParent(item
);
1544 GetClassNameW(item_parent
, buf
, 1024);
1545 ok(!lstrcmpW(buf
, floatnotifysinkW
), "Got %s\n", wine_dbgstr_w(buf
));
1546 item
= find_window(dlg_hwnd
, NULL
, text2W
);
1547 ok(item
!= NULL
, "Failed to find item.\n");
1548 item_parent
= GetParent(item
);
1549 GetClassNameW(item_parent
, buf
, 1024);
1550 ok(!lstrcmpW(buf
, floatnotifysinkW
), "Got %s\n", wine_dbgstr_w(buf
));
1551 item
= find_window(dlg_hwnd
, NULL
, radiobutton1W
);
1552 ok(item
!= NULL
, "Failed to find item.\n");
1553 item_parent
= GetParent(item
);
1554 GetClassNameW(item_parent
, buf
, 1024);
1555 ok(!lstrcmpW(buf
, RadioButtonListW
), "Got %s\n", wine_dbgstr_w(buf
));
1556 item_parent
= GetParent(item_parent
);
1557 GetClassNameW(item_parent
, buf
, 1024);
1558 ok(!lstrcmpW(buf
, floatnotifysinkW
), "Got %s\n", wine_dbgstr_w(buf
));
1560 item
= find_window(dlg_hwnd
, NULL
, pushbutton1W
);
1561 ok(item
== NULL
, "Found item: %p\n", item
);
1562 item
= find_window(dlg_hwnd
, NULL
, pushbutton2W
);
1563 ok(item
== NULL
, "Found item: %p\n", item
);
1564 item
= find_window(dlg_hwnd
, NULL
, comboboxitem1W
);
1565 ok(item
== NULL
, "Found item: %p\n", item
);
1566 item
= find_window(dlg_hwnd
, NULL
, comboboxitem2W
);
1567 ok(item
== NULL
, "Found item: %p\n", item
);
1568 item
= find_window(dlg_hwnd
, NULL
, radiobutton2W
);
1569 ok(item
== NULL
, "Found item: %p\n", item
);
1570 item
= find_window(dlg_hwnd
, NULL
, checkbutton1W
);
1571 ok(item
== NULL
, "Found item: %p\n", item
);
1572 item
= find_window(dlg_hwnd
, NULL
, editbox1W
);
1573 ok(item
== NULL
, "Found item: %p\n", item
);
1574 item
= find_window(dlg_hwnd
, NULL
, editbox2W
);
1575 ok(item
== NULL
, "Found item: %p\n", item
);
1576 item
= find_window(dlg_hwnd
, NULL
, textW
);
1577 ok(item
== NULL
, "Found item: %p\n", item
);
1578 item
= find_window(dlg_hwnd
, NULL
, separatorW
);
1579 ok(item
== NULL
, "Found item: %p\n", item
);
1580 item
= find_window(dlg_hwnd
, NULL
, visualgroup1W
);
1581 ok(item
== NULL
, "Found item: %p\n", item
);
1582 item
= find_window(dlg_hwnd
, NULL
, visualgroup2W
);
1583 todo_wine
ok(item
== NULL
, "Found item: %p\n", item
);
1585 br
= PostMessageW(dlg_hwnd
, WM_COMMAND
, IDCANCEL
, 0);
1589 static void test_customize(void)
1592 IFileDialogCustomize
*pfdc
;
1593 IFileDialogEventsImpl
*pfdeimpl
;
1594 IFileDialogEvents
*pfde
;
1596 CDCONTROLSTATEF cdstate
;
1600 UINT id_vgroup1
, id_text
, id_editbox1
;
1604 hr
= CoCreateInstance(&CLSID_FileOpenDialog
, NULL
, CLSCTX_INPROC_SERVER
,
1605 &IID_IFileDialog
, (void**)&pfod
);
1606 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1608 hr
= IFileDialog_QueryInterface(pfod
, &IID_IFileDialogCustomize
, (void**)&pfdc
);
1609 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1612 skip("Skipping IFileDialogCustomize tests.\n");
1613 IFileDialog_Release(pfod
);
1618 hr
= IFileDialogCustomize_AddPushButton(pfdc
, i
, pushbutton1W
);
1619 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1620 hr
= IFileDialogCustomize_AddPushButton(pfdc
, i
, pushbutton1W
);
1621 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1623 hr
= IFileDialog_QueryInterface(pfod
, &IID_IOleWindow
, (void**)&pow
);
1624 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
1625 hr
= IOleWindow_GetWindow(pow
, &dlg_hwnd
);
1626 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
1627 ok(dlg_hwnd
== NULL
, "NULL\n");
1628 IOleWindow_Release(pow
);
1630 cdstate
= 0xdeadbeef;
1631 hr
= IFileDialogCustomize_GetControlState(pfdc
, i
, &cdstate
);
1632 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1633 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1635 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1636 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
1638 hr
= IFileDialogCustomize_SetControlLabel(pfdc
, i
, label2
);
1639 ok(hr
== S_OK
, "got 0x%08x (control: %d).\n", hr
, i
);
1641 hr
= IFileDialogCustomize_EnableOpenDropDown(pfdc
, i
);
1642 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1643 hr
= IFileDialogCustomize_EnableOpenDropDown(pfdc
, ++i
);
1644 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1646 hr
= IFileDialogCustomize_EnableOpenDropDown(pfdc
, i
);
1647 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1648 hr
= IFileDialogCustomize_EnableOpenDropDown(pfdc
, i
+1);
1649 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1651 cdstate
= 0xdeadbeef;
1652 hr
= IFileDialogCustomize_GetControlState(pfdc
, i
, &cdstate
);
1653 ok(hr
== E_NOTIMPL
, "got 0x%08x.\n", hr
);
1654 ok(cdstate
== 0xdeadbeef, "got 0x%08x.\n", cdstate
);
1656 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1657 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1658 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1659 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
1661 cdstate
= 0xdeadbeef;
1662 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
1663 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1664 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1665 hr
= IFileDialogCustomize_SetControlItemState(pfdc
, i
, 0, 0);
1666 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1667 cdstate
= 0xdeadbeef;
1668 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
1669 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1670 ok(!cdstate
, "got 0x%08x.\n", cdstate
);
1671 hr
= IFileDialogCustomize_SetControlItemState(pfdc
, i
, 0, CDCS_ENABLEDVISIBLE
);
1672 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1673 cdstate
= 0xdeadbeef;
1674 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
1675 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1676 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1678 hr
= IFileDialogCustomize_SetControlLabel(pfdc
, i
, label2
);
1679 ok(hr
== E_NOTIMPL
, "got 0x%08x (control: %d).\n", hr
, i
);
1681 hr
= IFileDialogCustomize_AddMenu(pfdc
, i
, menuW
);
1682 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1683 hr
= IFileDialogCustomize_AddMenu(pfdc
, ++i
, label
);
1684 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1686 cdstate
= 0xdeadbeef;
1687 hr
= IFileDialogCustomize_GetControlState(pfdc
, i
, &cdstate
);
1688 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1689 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1691 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1692 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1693 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1694 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
1696 hr
= IFileDialogCustomize_SetControlLabel(pfdc
, i
, label2
);
1697 ok(hr
== S_OK
, "got 0x%08x (control: %d).\n", hr
, i
);
1699 hr
= IFileDialogCustomize_AddPushButton(pfdc
, i
, pushbutton2W
);
1700 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1701 hr
= IFileDialogCustomize_AddPushButton(pfdc
, ++i
, pushbutton2W
);
1702 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1704 cdstate
= 0xdeadbeef;
1705 hr
= IFileDialogCustomize_GetControlState(pfdc
, i
, &cdstate
);
1706 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1707 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1709 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1710 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
1712 hr
= IFileDialogCustomize_SetControlLabel(pfdc
, i
, label2
);
1713 ok(hr
== S_OK
, "got 0x%08x (control: %d).\n", hr
, i
);
1715 hr
= IFileDialogCustomize_AddComboBox(pfdc
, i
);
1716 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1717 hr
= IFileDialogCustomize_AddComboBox(pfdc
, ++i
);
1718 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1720 cdstate
= 0xdeadbeef;
1721 hr
= IFileDialogCustomize_GetControlState(pfdc
, i
, &cdstate
);
1722 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1723 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1725 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1726 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1727 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1728 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
1730 hr
= IFileDialogCustomize_SetControlLabel(pfdc
, i
, label2
);
1731 ok(hr
== S_OK
, "got 0x%08x (control: %d).\n", hr
, i
);
1733 hr
= IFileDialogCustomize_AddRadioButtonList(pfdc
, i
);
1734 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1735 hr
= IFileDialogCustomize_AddRadioButtonList(pfdc
, ++i
);
1736 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1738 cdstate
= 0xdeadbeef;
1739 hr
= IFileDialogCustomize_GetControlState(pfdc
, i
, &cdstate
);
1740 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1741 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1743 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, radiobutton1W
);
1744 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1745 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, radiobutton1W
);
1746 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
1748 hr
= IFileDialogCustomize_SetControlLabel(pfdc
, i
, radiobutton2W
);
1749 ok(hr
== S_OK
, "got 0x%08x (control: %d).\n", hr
, i
);
1751 hr
= IFileDialogCustomize_AddCheckButton(pfdc
, i
, label
, TRUE
);
1752 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1753 hr
= IFileDialogCustomize_AddCheckButton(pfdc
, ++i
, checkbutton1W
, TRUE
);
1754 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1756 cdstate
= 0xdeadbeef;
1757 hr
= IFileDialogCustomize_GetControlState(pfdc
, i
, &cdstate
);
1758 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1759 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1761 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1762 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
1764 hr
= IFileDialogCustomize_SetControlLabel(pfdc
, i
, checkbutton2W
);
1765 ok(hr
== S_OK
, "got 0x%08x (control: %d).\n", hr
, i
);
1770 hr
= IFileDialogCustomize_GetCheckButtonState(pfdc
, i
, &checked
);
1771 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1772 ok(checked
, "checkbox not checked.\n");
1774 hr
= IFileDialogCustomize_SetCheckButtonState(pfdc
, i
, FALSE
);
1775 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1777 hr
= IFileDialogCustomize_GetCheckButtonState(pfdc
, i
, &checked
);
1778 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1779 ok(!checked
, "checkbox checked.\n");
1781 hr
= IFileDialogCustomize_SetCheckButtonState(pfdc
, i
, TRUE
);
1782 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1784 hr
= IFileDialogCustomize_GetCheckButtonState(pfdc
, i
, &checked
);
1785 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1786 ok(checked
, "checkbox not checked.\n");
1789 hr
= IFileDialogCustomize_AddEditBox(pfdc
, i
, label
);
1790 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1791 hr
= IFileDialogCustomize_AddEditBox(pfdc
, ++i
, editbox1W
);
1792 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1794 cdstate
= 0xdeadbeef;
1795 hr
= IFileDialogCustomize_GetControlState(pfdc
, i
, &cdstate
);
1796 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1797 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1799 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1800 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
1802 /* Does not affect the text in the editbox */
1803 hr
= IFileDialogCustomize_SetControlLabel(pfdc
, i
, editbox2W
);
1804 ok(hr
== S_OK
, "got 0x%08x (control: %d).\n", hr
, i
);
1806 hr
= IFileDialogCustomize_GetEditBoxText(pfdc
, i
, &tmpstr
);
1807 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1810 ok(!lstrcmpW(tmpstr
, editbox1W
), "got %s.\n", wine_dbgstr_w(tmpstr
));
1811 CoTaskMemFree(tmpstr
);
1814 hr
= IFileDialogCustomize_SetEditBoxText(pfdc
, i
, label2
);
1815 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1817 hr
= IFileDialogCustomize_GetEditBoxText(pfdc
, i
, &tmpstr
);
1818 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1821 ok(!lstrcmpW(tmpstr
, label2
), "got %s.\n", wine_dbgstr_w(tmpstr
));
1822 CoTaskMemFree(tmpstr
);
1825 hr
= IFileDialogCustomize_AddSeparator(pfdc
, i
);
1826 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1827 hr
= IFileDialogCustomize_AddSeparator(pfdc
, ++i
);
1828 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1830 cdstate
= 0xdeadbeef;
1831 hr
= IFileDialogCustomize_GetControlState(pfdc
, i
, &cdstate
);
1832 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1833 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1835 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1836 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
1838 hr
= IFileDialogCustomize_SetControlLabel(pfdc
, i
, separatorW
);
1839 ok(hr
== S_OK
, "got 0x%08x (control: %d).\n", hr
, i
);
1841 hr
= IFileDialogCustomize_AddText(pfdc
, i
, label
);
1842 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1843 hr
= IFileDialogCustomize_AddText(pfdc
, ++i
, textW
);
1844 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1846 cdstate
= 0xdeadbeef;
1847 hr
= IFileDialogCustomize_GetControlState(pfdc
, i
, &cdstate
);
1848 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1849 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1851 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1852 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
1854 hr
= IFileDialogCustomize_SetControlLabel(pfdc
, i
, text2W
);
1855 ok(hr
== S_OK
, "got 0x%08x (control: %d).\n", hr
, i
);
1857 hr
= IFileDialogCustomize_StartVisualGroup(pfdc
, i
, label
);
1858 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1859 hr
= IFileDialogCustomize_StartVisualGroup(pfdc
, ++i
, visualgroup1W
);
1860 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1862 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1863 ok(hr
== E_NOINTERFACE
, "got 0x%08x.\n", hr
);
1865 hr
= IFileDialogCustomize_SetControlLabel(pfdc
, i
, visualgroup2W
);
1866 ok(hr
== S_OK
, "got 0x%08x (control: %d).\n", hr
, i
);
1868 cdstate
= 0xdeadbeef;
1869 hr
= IFileDialogCustomize_GetControlState(pfdc
, i
, &cdstate
);
1870 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1871 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1873 hr
= IFileDialogCustomize_StartVisualGroup(pfdc
, ++i
, label
);
1874 ok(hr
== E_UNEXPECTED
, "got 0x%08x.\n", hr
);
1875 hr
= IFileDialogCustomize_EndVisualGroup(pfdc
);
1876 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1878 i
++; /* Nonexisting control */
1879 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, 0, label
);
1880 todo_wine
ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
1881 hr
= IFileDialogCustomize_SetControlLabel(pfdc
, i
, label2
);
1882 ok(hr
== E_INVALIDARG
, "got 0x%08x (control: %d).\n", hr
, i
);
1883 cdstate
= 0xdeadbeef;
1884 hr
= IFileDialogCustomize_GetControlState(pfdc
, i
, &cdstate
);
1885 todo_wine
ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
1886 ok(cdstate
== 0xdeadbeef, "got 0x%08x.\n", cdstate
);
1888 pfde
= IFileDialogEvents_Constructor();
1889 pfdeimpl
= impl_from_IFileDialogEvents(pfde
);
1890 pfdeimpl
->events_test
= IFDEVENT_TEST1
;
1891 hr
= IFileDialog_Advise(pfod
, pfde
, &cookie
);
1892 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
1894 hr
= IFileDialog_Show(pfod
, NULL
);
1895 ok(hr
== HRESULT_FROM_WIN32(ERROR_CANCELLED
), "Got 0x%08x\n", hr
);
1897 hr
= IFileDialog_Unadvise(pfod
, cookie
);
1898 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
1900 IFileDialogEvents_Release(pfde
);
1901 IFileDialogCustomize_Release(pfdc
);
1902 ref
= IFileDialog_Release(pfod
);
1903 ok(!ref
, "Refcount not zero (%d).\n", ref
);
1906 hr
= CoCreateInstance(&CLSID_FileOpenDialog
, NULL
, CLSCTX_INPROC_SERVER
,
1907 &IID_IFileDialog
, (void**)&pfod
);
1908 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1910 hr
= IFileDialog_QueryInterface(pfod
, &IID_IFileDialogCustomize
, (void**)&pfdc
);
1911 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1914 hr
= IFileDialogCustomize_AddMenu(pfdc
, ++i
, label
);
1915 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1921 for(j
= 0; j
< 10; j
++)
1923 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, j
, label
);
1924 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1927 hr
= IFileDialogCustomize_GetSelectedControlItem(pfdc
, i
, &selected
);
1928 ok(hr
== E_NOTIMPL
, "got 0x%08x.\n", hr
);
1930 cdstate
= 0xdeadbeef;
1931 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
1932 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1933 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1934 hr
= IFileDialogCustomize_SetControlItemState(pfdc
, i
, 0, 0);
1935 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1936 cdstate
= 0xdeadbeef;
1937 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
1938 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1939 ok(cdstate
== 0, "got 0x%08x.\n", cdstate
);
1940 hr
= IFileDialogCustomize_SetControlItemState(pfdc
, i
, 0, CDCS_ENABLEDVISIBLE
);
1941 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1942 cdstate
= 0xdeadbeef;
1943 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
1944 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1945 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1947 hr
= IFileDialogCustomize_RemoveAllControlItems(pfdc
, i
);
1948 ok(hr
== E_NOTIMPL
, "got 0x%08x.\n", hr
);
1950 for(j
= 0; j
< 10; j
++)
1952 hr
= IFileDialogCustomize_RemoveControlItem(pfdc
, i
, j
);
1953 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1956 hr
= IFileDialogCustomize_AddPushButton(pfdc
, ++i
, label
);
1957 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1958 hr
= IFileDialogCustomize_AddComboBox(pfdc
, ++i
);
1959 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1962 DWORD selected
= -1;
1965 for(j
= 0; j
< 10; j
++)
1967 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, j
, label
);
1968 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1971 hr
= IFileDialogCustomize_GetSelectedControlItem(pfdc
, i
, &selected
);
1972 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
1973 ok(selected
== -1, "got %d.\n", selected
);
1975 cdstate
= 0xdeadbeef;
1976 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
1977 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1978 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1979 hr
= IFileDialogCustomize_SetControlItemState(pfdc
, i
, 0, 0);
1980 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1981 cdstate
= 0xdeadbeef;
1982 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
1983 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1984 ok(cdstate
== 0, "got 0x%08x.\n", cdstate
);
1985 hr
= IFileDialogCustomize_SetControlItemState(pfdc
, i
, 0, CDCS_ENABLEDVISIBLE
);
1986 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1987 cdstate
= 0xdeadbeef;
1988 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
1989 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1990 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
1992 for(j
= 0; j
< 10; j
++)
1994 hr
= IFileDialogCustomize_SetSelectedControlItem(pfdc
, i
, j
);
1995 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1996 hr
= IFileDialogCustomize_GetSelectedControlItem(pfdc
, i
, &selected
);
1997 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
1998 ok(selected
== j
, "got %d.\n", selected
);
2001 hr
= IFileDialogCustomize_SetSelectedControlItem(pfdc
, i
, j
);
2002 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
2004 hr
= IFileDialogCustomize_RemoveAllControlItems(pfdc
, i
);
2005 ok(hr
== E_NOTIMPL
, "got 0x%08x.\n", hr
);
2007 for(j
= 0; j
< 10; j
++)
2009 hr
= IFileDialogCustomize_RemoveControlItem(pfdc
, i
, j
);
2010 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2014 hr
= IFileDialogCustomize_AddRadioButtonList(pfdc
, ++i
);
2015 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2018 DWORD selected
= -1;
2021 for(j
= 0; j
< 10; j
++)
2023 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, j
, label
);
2024 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2027 hr
= IFileDialogCustomize_GetSelectedControlItem(pfdc
, i
, &selected
);
2028 ok(hr
== E_FAIL
, "got 0x%08x.\n", hr
);
2029 ok(selected
== -1, "got %d.\n", selected
);
2031 cdstate
= 0xdeadbeef;
2032 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
2033 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2034 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2035 hr
= IFileDialogCustomize_SetControlItemState(pfdc
, i
, 0, 0);
2036 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2037 cdstate
= 0xdeadbeef;
2038 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
2039 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2040 ok(cdstate
== 0, "got 0x%08x.\n", cdstate
);
2041 hr
= IFileDialogCustomize_SetControlItemState(pfdc
, i
, 0, CDCS_ENABLEDVISIBLE
);
2042 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2043 cdstate
= 0xdeadbeef;
2044 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
2045 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2046 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2048 for(j
= 0; j
< 10; j
++)
2050 hr
= IFileDialogCustomize_SetSelectedControlItem(pfdc
, i
, j
);
2051 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2052 hr
= IFileDialogCustomize_GetSelectedControlItem(pfdc
, i
, &selected
);
2053 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2054 ok(selected
== j
, "got %d.\n", selected
);
2057 hr
= IFileDialogCustomize_SetSelectedControlItem(pfdc
, i
, j
);
2058 ok(hr
== E_INVALIDARG
, "got 0x%08x.\n", hr
);
2060 hr
= IFileDialogCustomize_RemoveAllControlItems(pfdc
, i
);
2061 ok(hr
== E_NOTIMPL
, "got 0x%08x.\n", hr
);
2063 for(j
= 0; j
< 10; j
++)
2065 hr
= IFileDialogCustomize_RemoveControlItem(pfdc
, i
, j
);
2066 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2069 hr
= IFileDialogCustomize_EnableOpenDropDown(pfdc
, ++i
);
2070 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2073 DWORD selected
= -1;
2076 for(j
= 0; j
< 10; j
++)
2078 hr
= IFileDialogCustomize_AddControlItem(pfdc
, i
, j
, label
);
2079 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2082 hr
= IFileDialogCustomize_GetSelectedControlItem(pfdc
, i
, &selected
);
2083 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2084 ok(selected
== 0, "got %d.\n", selected
);
2086 cdstate
= 0xdeadbeef;
2087 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
2088 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2089 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2090 hr
= IFileDialogCustomize_SetControlItemState(pfdc
, i
, 0, 0);
2091 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2092 cdstate
= 0xdeadbeef;
2093 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
2094 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2095 ok(cdstate
== 0, "got 0x%08x.\n", cdstate
);
2096 hr
= IFileDialogCustomize_SetControlItemState(pfdc
, i
, 0, CDCS_ENABLEDVISIBLE
);
2097 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2098 cdstate
= 0xdeadbeef;
2099 hr
= IFileDialogCustomize_GetControlItemState(pfdc
, i
, 0, &cdstate
);
2100 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2101 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2102 hr
= IFileDialogCustomize_SetSelectedControlItem(pfdc
, i
, 0);
2103 todo_wine
ok(hr
== E_NOTIMPL
, "got 0x%08x.\n", hr
);
2105 hr
= IFileDialogCustomize_RemoveAllControlItems(pfdc
, i
);
2106 ok(hr
== E_NOTIMPL
, "got 0x%08x.\n", hr
);
2108 for(j
= 0; j
< 10; j
++)
2110 hr
= IFileDialogCustomize_RemoveControlItem(pfdc
, i
, j
);
2111 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2115 IFileDialogCustomize_Release(pfdc
);
2116 ref
= IFileDialog_Release(pfod
);
2117 ok(!ref
, "Refcount not zero (%d).\n", ref
);
2120 /* Some more tests for VisualGroup behavior */
2121 hr
= CoCreateInstance(&CLSID_FileOpenDialog
, NULL
, CLSCTX_INPROC_SERVER
,
2122 &IID_IFileDialog
, (void**)&pfod
);
2123 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2125 hr
= IFileDialog_QueryInterface(pfod
, &IID_IFileDialogCustomize
, (void**)&pfdc
);
2126 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2130 hr
= IFileDialogCustomize_StartVisualGroup(pfdc
, id_vgroup1
, visualgroup1W
);
2131 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2133 cdstate
= 0xdeadbeef;
2134 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_vgroup1
, &cdstate
);
2135 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2136 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2139 hr
= IFileDialogCustomize_AddText(pfdc
, id_text
, label
);
2140 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2142 cdstate
= 0xdeadbeef;
2143 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_text
, &cdstate
);
2144 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2145 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2148 hr
= IFileDialogCustomize_AddEditBox(pfdc
, id_editbox1
, editbox1W
);
2149 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2151 cdstate
= 0xdeadbeef;
2152 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_editbox1
, &cdstate
);
2153 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2154 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2157 /* Set all Visible but not Enabled */
2158 hr
= IFileDialogCustomize_SetControlState(pfdc
, id_vgroup1
, CDCS_VISIBLE
);
2159 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2161 cdstate
= 0xdeadbeef;
2162 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_vgroup1
, &cdstate
);
2163 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2164 ok(cdstate
== CDCS_VISIBLE
, "got 0x%08x.\n", cdstate
);
2165 cdstate
= 0xdeadbeef;
2167 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_text
, &cdstate
);
2168 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2169 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2171 cdstate
= 0xdeadbeef;
2172 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_editbox1
, &cdstate
);
2173 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2174 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2176 /* Set text to Visible but not Enabled */
2177 hr
= IFileDialogCustomize_SetControlState(pfdc
, id_text
, CDCS_VISIBLE
);
2178 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2180 cdstate
= 0xdeadbeef;
2181 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_vgroup1
, &cdstate
);
2182 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2183 ok(cdstate
== CDCS_VISIBLE
, "got 0x%08x.\n", cdstate
);
2184 cdstate
= 0xdeadbeef;
2186 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_text
, &cdstate
);
2187 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2188 ok(cdstate
== CDCS_VISIBLE
, "got 0x%08x.\n", cdstate
);
2190 cdstate
= 0xdeadbeef;
2191 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_editbox1
, &cdstate
);
2192 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2193 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2195 /* Set vgroup to inactive */
2196 hr
= IFileDialogCustomize_SetControlState(pfdc
, id_vgroup1
, CDCS_INACTIVE
);
2197 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2199 cdstate
= 0xdeadbeef;
2200 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_vgroup1
, &cdstate
);
2201 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2202 ok(cdstate
== CDCS_INACTIVE
, "got 0x%08x.\n", cdstate
);
2204 cdstate
= 0xdeadbeef;
2205 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_text
, &cdstate
);
2206 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2207 ok(cdstate
== CDCS_VISIBLE
, "got 0x%08x.\n", cdstate
);
2209 cdstate
= 0xdeadbeef;
2210 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_editbox1
, &cdstate
);
2211 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2212 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2214 /* Set vgroup to Enabled and Visible again */
2215 hr
= IFileDialogCustomize_SetControlState(pfdc
, id_vgroup1
, CDCS_ENABLEDVISIBLE
);
2216 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2218 cdstate
= 0xdeadbeef;
2219 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_vgroup1
, &cdstate
);
2220 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2221 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2223 cdstate
= 0xdeadbeef;
2224 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_text
, &cdstate
);
2225 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2226 ok(cdstate
== CDCS_VISIBLE
, "got 0x%08x.\n", cdstate
);
2228 cdstate
= 0xdeadbeef;
2229 hr
= IFileDialogCustomize_GetControlState(pfdc
, id_editbox1
, &cdstate
);
2230 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2231 ok(cdstate
== CDCS_ENABLEDVISIBLE
, "got 0x%08x.\n", cdstate
);
2233 hr
= IFileDialogCustomize_MakeProminent(pfdc
, id_vgroup1
);
2234 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2236 IFileDialogCustomize_Release(pfdc
);
2237 ref
= IFileDialog_Release(pfod
);
2238 ok(!ref
, "Refcount not zero (%d).\n", ref
);
2241 static void test_persistent_state(void)
2246 hr
= CoCreateInstance(&CLSID_FileOpenDialog
, NULL
, CLSCTX_INPROC_SERVER
,
2247 &IID_IFileDialog
, (void**)&fd
);
2248 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2252 /* crashes at least on Win8 */
2253 hr
= IFileDialog_SetClientGuid(fd
, NULL
);
2256 hr
= IFileDialog_SetClientGuid(fd
, &IID_IUnknown
);
2257 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2259 hr
= IFileDialog_SetClientGuid(fd
, &IID_NULL
);
2260 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2262 IFileDialog_Release(fd
);
2265 static void test_overwrite(void)
2267 static const WCHAR filename_winetest
[] = {'w','i','n','e','t','e','s','t','.','o','v','w',0};
2268 IFileDialogEventsImpl
*pfdeimpl
;
2269 IFileDialogEvents
*pfde
;
2273 IShellItem
*psi_current
;
2274 WCHAR buf
[MAX_PATH
];
2277 GetCurrentDirectoryW(MAX_PATH
, buf
);
2278 ok(!!pSHCreateItemFromParsingName
, "SHCreateItemFromParsingName is missing.\n");
2279 hr
= pSHCreateItemFromParsingName(buf
, NULL
, &IID_IShellItem
, (void**)&psi_current
);
2280 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
2282 touch_file(filename_winetest
);
2284 /* FOS_OVERWRITEPROMPT has no effect on open dialog */
2285 hr
= CoCreateInstance(&CLSID_FileOpenDialog
, NULL
, CLSCTX_INPROC_SERVER
,
2286 &IID_IFileDialog
, (void**)&fd
);
2287 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2289 hr
= IFileDialog_SetOptions(fd
, FOS_OVERWRITEPROMPT
| FOS_NOCHANGEDIR
);
2290 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2292 hr
= IFileDialog_SetFolder(fd
, psi_current
);
2293 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2295 pfde
= IFileDialogEvents_Constructor();
2296 pfdeimpl
= impl_from_IFileDialogEvents(pfde
);
2297 pfdeimpl
->set_filename
= filename_winetest
;
2298 hr
= IFileDialog_Advise(fd
, pfde
, &cookie
);
2299 ok(hr
== S_OK
, "Advise failed: Got 0x%08x\n", hr
);
2301 hr
= IFileDialog_Show(fd
, NULL
);
2302 ok(hr
== S_OK
, "Show failed: Got 0x%08x\n", hr
);
2304 ok(!pfdeimpl
->OnOverwrite
, "got %u overwrite events\n", pfdeimpl
->OnOverwrite
);
2305 ok(pfdeimpl
->OnFileOk
== 1, "got %u ok events\n", pfdeimpl
->OnFileOk
);
2307 hr
= IFileDialog_GetFileName(fd
, &filename
);
2308 ok(hr
== S_OK
, "GetFileName failed: Got 0x%08x\n", hr
);
2309 ok(!lstrcmpW(filename
, filename_winetest
), "Got %s\n", wine_dbgstr_w(filename
));
2310 CoTaskMemFree(filename
);
2312 hr
= IFileDialog_Unadvise(fd
, cookie
);
2313 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2315 IFileDialog_Release(fd
);
2317 IFileDialogEvents_Release(pfde
);
2319 /* Save dialog doesn't check for overwrite without FOS_OVERWRITEPROMPT set */
2320 hr
= CoCreateInstance(&CLSID_FileSaveDialog
, NULL
, CLSCTX_INPROC_SERVER
,
2321 &IID_IFileDialog
, (void**)&fd
);
2322 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2324 hr
= IFileDialog_SetOptions(fd
, FOS_NOREADONLYRETURN
| FOS_PATHMUSTEXIST
| FOS_NOCHANGEDIR
);
2325 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2327 hr
= IFileDialog_SetFolder(fd
, psi_current
);
2328 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2330 pfde
= IFileDialogEvents_Constructor();
2331 pfdeimpl
= impl_from_IFileDialogEvents(pfde
);
2332 pfdeimpl
->set_filename
= filename_winetest
;
2333 hr
= IFileDialog_Advise(fd
, pfde
, &cookie
);
2334 ok(hr
== S_OK
, "Advise failed: Got 0x%08x\n", hr
);
2336 hr
= IFileDialog_Show(fd
, NULL
);
2337 ok(hr
== S_OK
, "Show failed: Got 0x%08x\n", hr
);
2339 ok(!pfdeimpl
->OnOverwrite
, "got %u overwrite events\n", pfdeimpl
->OnOverwrite
);
2340 ok(pfdeimpl
->OnFileOk
== 1, "got %u ok events\n", pfdeimpl
->OnFileOk
);
2342 hr
= IFileDialog_GetFileName(fd
, &filename
);
2343 ok(hr
== S_OK
, "GetFileName failed: Got 0x%08x\n", hr
);
2344 ok(!lstrcmpW(filename
, filename_winetest
), "Got %s\n", wine_dbgstr_w(filename
));
2345 CoTaskMemFree(filename
);
2347 hr
= IFileDialog_Unadvise(fd
, cookie
);
2348 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2350 IFileDialog_Release(fd
);
2352 IFileDialogEvents_Release(pfde
);
2354 /* Save dialog with FOS_OVERWRITEPROMPT set */
2355 hr
= CoCreateInstance(&CLSID_FileSaveDialog
, NULL
, CLSCTX_INPROC_SERVER
,
2356 &IID_IFileDialog
, (void**)&fd
);
2357 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2359 hr
= IFileDialog_SetFolder(fd
, psi_current
);
2360 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2362 pfde
= IFileDialogEvents_Constructor();
2363 pfdeimpl
= impl_from_IFileDialogEvents(pfde
);
2364 pfdeimpl
->set_filename
= filename_winetest
;
2365 hr
= IFileDialog_Advise(fd
, pfde
, &cookie
);
2366 ok(hr
== S_OK
, "Advise failed: Got 0x%08x\n", hr
);
2368 hr
= IFileDialog_Show(fd
, NULL
);
2369 ok(hr
== S_OK
, "Show failed: Got 0x%08x\n", hr
);
2371 ok(pfdeimpl
->OnOverwrite
== 1, "got %u overwrite events\n", pfdeimpl
->OnOverwrite
);
2372 ok(pfdeimpl
->OnFileOk
== 1, "got %u ok events\n", pfdeimpl
->OnFileOk
);
2374 hr
= IFileDialog_GetFileName(fd
, &filename
);
2375 ok(hr
== S_OK
, "GetFileName failed: Got 0x%08x\n", hr
);
2376 ok(!lstrcmpW(filename
, filename_winetest
), "Got %s\n", wine_dbgstr_w(filename
));
2377 CoTaskMemFree(filename
);
2379 hr
= IFileDialog_Unadvise(fd
, cookie
);
2380 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2382 IFileDialog_Release(fd
);
2384 IFileDialogEvents_Release(pfde
);
2386 DeleteFileW(filename_winetest
);
2388 /* Save dialog with FOS_OVERWRITEPROMPT set but without existing file */
2389 hr
= CoCreateInstance(&CLSID_FileSaveDialog
, NULL
, CLSCTX_INPROC_SERVER
,
2390 &IID_IFileDialog
, (void**)&fd
);
2391 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2393 hr
= IFileDialog_SetFolder(fd
, psi_current
);
2394 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2396 pfde
= IFileDialogEvents_Constructor();
2397 pfdeimpl
= impl_from_IFileDialogEvents(pfde
);
2398 pfdeimpl
->set_filename
= filename_winetest
;
2399 hr
= IFileDialog_Advise(fd
, pfde
, &cookie
);
2400 ok(hr
== S_OK
, "Advise failed: Got 0x%08x\n", hr
);
2402 hr
= IFileDialog_Show(fd
, NULL
);
2403 ok(hr
== S_OK
, "Show failed: Got 0x%08x\n", hr
);
2405 ok(!pfdeimpl
->OnOverwrite
, "got %u overwrite events\n", pfdeimpl
->OnOverwrite
);
2406 ok(pfdeimpl
->OnFileOk
== 1, "got %u ok events\n", pfdeimpl
->OnFileOk
);
2408 hr
= IFileDialog_GetFileName(fd
, &filename
);
2409 ok(hr
== S_OK
, "GetFileName failed: Got 0x%08x\n", hr
);
2410 ok(!lstrcmpW(filename
, filename_winetest
), "Got %s\n", wine_dbgstr_w(filename
));
2411 CoTaskMemFree(filename
);
2413 hr
= IFileDialog_Unadvise(fd
, cookie
);
2414 ok(hr
== S_OK
, "got 0x%08x.\n", hr
);
2416 IFileDialog_Release(fd
);
2418 IFileDialogEvents_Release(pfde
);
2420 IShellItem_Release(psi_current
);
2425 OleInitialize(NULL
);
2426 init_function_pointers();
2428 if(test_instantiation())
2435 test_persistent_state();
2439 skip("Skipping all Item Dialog tests.\n");