diff --git a/include/wx/msw/filedlg.h b/include/wx/msw/filedlg.h index 74a708e9f7..0c9ba46228 100644 --- a/include/wx/msw/filedlg.h +++ b/include/wx/msw/filedlg.h @@ -51,7 +51,7 @@ private: // called when the dialog is created void MSWOnInitDialogHook(WXHWND hwnd); - // called from the hook procedure on CDN_INITDONE reception + // called when the dialog initialization is fully done void MSWOnInitDone(WXHWND hDlg); // called when the currently selected file changes in the dialog diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index c12adb2731..297c0d1eef 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -1741,6 +1741,8 @@ void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) wxEmptyString, wxEmptyString, wildcards, wxFD_OPEN|wxFD_MULTIPLE); + dialog.Centre(wxCENTER_ON_SCREEN); + if (dialog.ShowModal() == wxID_OK) { wxArrayString paths, filenames; diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index f7e45c4d41..66ed09ab53 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -218,7 +218,8 @@ class wxFileDialogMSWData public: explicit wxFileDialogMSWData(wxFileDialog* fileDialog) #if wxUSE_IFILEOPENDIALOG - : m_fileDialog(fileDialog) + : m_fileDialog(fileDialog), + m_typeAlreadyChanged(false) #endif // wxUSE_IFILEOPENDIALOG { m_bMovedWindow = false; @@ -263,6 +264,24 @@ public: wxSTDMETHODIMP OnTypeChange(IFileDialog* pfd) wxOVERRIDE { + // There is no special notification for the dialog initialization, but + // this function is always called when it's shown, so use it for + // generating this notification as well. + if ( !m_typeAlreadyChanged ) + { + m_typeAlreadyChanged = true; + + wxCOMPtr window; + HRESULT hr = pfd->QueryInterface(wxIID_PPV_ARGS(IOleWindow, &window)); + if ( SUCCEEDED(hr) ) + { + HWND hwnd; + hr = window->GetWindow(&hwnd); + if ( SUCCEEDED(hr) ) + m_fileDialog->MSWOnInitDone(hwnd); + } + } + m_fileDialog->MSWOnTypeChange(FileDialogGetFileTypeIndex(pfd)); return S_OK; @@ -273,6 +292,8 @@ public: wxFileDialog* const m_fileDialog; + bool m_typeAlreadyChanged; + DECLARE_IUNKNOWN_METHODS; #endif // wxUSE_IFILEOPENDIALOG @@ -582,11 +603,11 @@ int wxFileDialog::ShowModal() /* We need to use the old style dialog in order to use a hook function - which allows us to position it or use custom controls in it but, if - possible, we prefer to use the new style one instead. + which allows us to use custom controls in it but, if possible, we + prefer to use the new style one instead. */ #if wxUSE_IFILEOPENDIALOG - if ( (!m_data || !m_data->m_bMovedWindow) && !HasExtraControlCreator() ) + if ( !HasExtraControlCreator() ) { const int rc = ShowIFileDialog(hWndParent); if ( rc != wxID_NONE )