diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index be2df982c6..1c16505ce5 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -654,23 +654,30 @@ int wxFileDialog::ShowModal() } } + // Create a temporary struct to restore the CWD when we exit this function // store off before the standard windows dialog can possibly change it - const wxString cwdOrig = wxGetCwd(); - - //== Execute FileDialog >>================================================= - - if ( !ShowCommFileDialog(&of, m_windowStyle) ) - return wxID_CANCEL; + struct CwdRestore + { + wxString value; + ~CwdRestore() + { + if (!value.empty()) + wxSetWorkingDirectory(value); + } + } cwdOrig; // GetOpenFileName will always change the current working directory on // (according to MSDN) "Windows NT 4.0/2000/XP" because the flag // OFN_NOCHANGEDIR has no effect. If the user did not specify // wxFD_CHANGE_DIR let's restore the current working directory to what it // was before the dialog was shown. - if ( msw_flags & OFN_NOCHANGEDIR ) - { - wxSetWorkingDirectory(cwdOrig); - } + if (msw_flags & OFN_NOCHANGEDIR) + cwdOrig.value = wxGetCwd(); + + //== Execute FileDialog >>================================================= + + if ( !ShowCommFileDialog(&of, m_windowStyle) ) + return wxID_CANCEL; m_fileNames.Empty();