CFileDialog::OnFolderChange() doesn't work as expected (Windows C++/MFC)

148 Views Asked by At

C++/MFC, Windows 11. Visual Studio 2022 17.4.3.

I'm using CFileDialog to allow user to chose a file. I want to be notified whenever the user changes directories (folders), but I can't get OnFolderChange to work. I expect OnFolderChange() to be called every time user selects a folder, but it is not called.

What do I need to do to get the notification when user switches folders?

Here is sample code.

Header:

// Browsing_test.h

class P
{
public:
    int BrowseTest(void);
    virtual void OnFolderChange();
};
#include "Browsing_test.h"

int P::BrowseTest(void)
{
    DWORD flags = OFN_CREATEPROMPT | OFN_HIDEREADONLY | OFN_ENABLESIZING;
    CFileDialog dlg(TRUE, NULL/*defaultExt*/, NULL/*defaultFiles*/, flags, NULL/*fileTypes*/, nullptr/* pParentWnd*/, 0/*dwSize*/, TRUE/*bVistaStyle*/);
    int resultDebug = (int)dlg.DoModal();
    return resultDebug;
}

void P::OnFolderChange()
{
    bool stopHere = true; // NEVER GETS HERE
}
0

There are 0 best solutions below