diff --git a/include/wx/msw/private/filedialog.h b/include/wx/msw/private/filedialog.h index a7adb6ae43..fe02dc34ef 100644 --- a/include/wx/msw/private/filedialog.h +++ b/include/wx/msw/private/filedialog.h @@ -66,6 +66,7 @@ public: Show(HWND owner, int options, wxArrayString* pathsOut, wxString* pathOut); // Behave as IFileDialog. + IFileDialog* Get() const { return m_fileDialog.Get(); } IFileDialog* operator->() const { return m_fileDialog.Get(); } private: diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index ee7b53e81f..698ebf4fe8 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -143,6 +143,31 @@ void RestoreExceptionPolicy() #endif // wxUSE_DYNLIB_CLASS } +#if wxUSE_IFILEOPENDIALOG + +// ---------------------------------------------------------------------------- +// Various IFileDialog-related helpers: they're only used here for now, but if +// they're ever needed in wxDirDialog too, we should put move them to +// wx/msw/private/filedialog.h +// ---------------------------------------------------------------------------- + +// Return 1-based index of the currently selected file type. +UINT FileDialogGetFileTypeIndex(IFileDialog* fileDialog) +{ + UINT nFilterIndex; + HRESULT hr = fileDialog->GetFileTypeIndex(&nFilterIndex); + if ( FAILED(hr) ) + { + wxLogApiError(wxS("IFileDialog::GetFileTypeIndex"), hr); + + nFilterIndex = 0; + } + + return nFilterIndex; +} + +#endif // wxUSE_IFILEOPENDIALOG + } // unnamed namespace // ---------------------------------------------------------------------------- @@ -833,19 +858,11 @@ int wxFileDialog::ShowIFileDialog(WXHWND hWndParent) const int rc = fileDialog.Show(hWndParent, options, &m_fileNames, &m_path); if ( rc == wxID_OK ) { - UINT nFilterIndex; - hr = fileDialog->GetFileTypeIndex(&nFilterIndex); - if ( SUCCEEDED(hr) ) - { - // As with the common dialog, the index is 1-based here. - m_filterIndex = nFilterIndex - 1; - } - else - { - wxLogApiError(wxS("IFileDialog::GetFileTypeIndex"), hr); - - m_filterIndex = 0; - } + // As with the common dialog, the index is 1-based here, but don't make + // it negative if we somehow failed to retrieve it at all. + m_filterIndex = FileDialogGetFileTypeIndex(fileDialog.Get()); + if ( m_filterIndex > 0 ) + m_filterIndex--; if ( HasFlag(wxFD_MULTIPLE) ) {