0

I have an Visual Studio 2022 MFC application in which the user can specify the default folder locations of certain types of files used/handled by the application (e.g. txt, jpeg, xls...). The user can specify the default directories via a dedicated dialog with 'Browse Folder' edit boxes for each of the various file types. The details of the selected folders are stored in a Windows Registry entry.

When the user launches the familiar 'File Open' dialog the file type filter by default is set to display .txt files. AND ALSO the directory/folder path displays the default path specified by the user, for .txt files.

BUT IF it is possible I would like the displayed directory path/default folder to automatically update/change IF the user changes the file type filter (e.g. switches from .txt files to .bmp).

Is it possible to do this with the MFC 'File Ope'n dialog? Thanks in advance to anyoen who can help.

DavidH
  • 97
  • 6
  • 1
    You can handle the [`CDN_TYPECHANGE`](https://learn.microsoft.com/en-us/windows/win32/dlgbox/cdn-typechange) notification, and switch to a different directory. If you are using an Explorer-style **Open** or **Save as** dialog. From the question it's not clear, which type of dialog you are using. I believe MFC wraps both the old and new-ish [Common Item Dialog](https://learn.microsoft.com/en-us/windows/win32/shell/common-file-dialog). – IInspectable Dec 23 '21 at 14:34
  • Thank you for the speedy reply. My application uses 'Explorer' style File Open dialog (and also for 'File Save'). I will investigate your suggestion. – DavidH Dec 23 '21 at 14:55
  • 1
    So create a new class, derived from the file dialog and handle the message referred to in the comments. – Andrew Truckle Dec 24 '21 at 07:26
  • I created new class derived from CFileDialog and overrode: virtual void OnTypeChange(); It goes there after the file extension type filter is changed - but don't know how to change the directory path string. I am trying to use 'ApplyOFNToShellDialog()' to change the displayed directory path. As a test I tried to change the dialog title in response to the file type filter change using this code: virtual void OnTypeChange() UpdateOFNFromShellDialog(); // here modifying the m_ofn to change dialog ApplyOFNToShellDialog(); but, it crashes on the 'ApplyOFNToShellDialog()' call. – DavidH Dec 27 '21 at 18:22
  • See the answer that I put together today for the other question (linked at the top). – Andrew Truckle Jan 02 '23 at 22:32

0 Answers0