It seems a fairly big omission for Microsoft to have left out any sort of user data associated with the IFileDialog
callbacks, but that does seem to be the case.
I'm assuming that simply calling GetSelectedItems()
once the dialog returns is something you don't want to do for some reason - because that would obviously be the simplest solution.
From a quick look at the docs one way you may be able to pass data back from the event callback is using the owner window that you pass to IFileDialog::Show()
(which is actually IModalWindow::Show()
).
In the event handler, you get given the IFileDialog*
pointer. From this, you can QI the address of the IOleWindow
interface which will give you the dialog's window:
IFACEMETHODIMP OnFileOk(IFileDialog *pfd)
{
CComPtr<IOleWindow> pWindow;
if (SUCCEEDED(pfd->QueryInterface(IID_IOleWindow, reinterpret_cast<void**>(&pWindow))))
{
HWND hwndDlg;
if (SUCCEEDED(pWindow->GetWindow(&hwndDlg)))
{
HWND hwndOwner;
if (hwndOwner = GetWindow(hwndDlg, GW_OWNER))
{
// hwndOwner is the owner window of the dialog
}
}
}
// more code
}
Now assuming that hwndOwner
is your own window, you can associate any data you like with it using SetProp()
/GetProp()
- so you could use this as a mechanism to pass data back from within the callback.