Reputation: 867
C++/MFC, Windows 11. Visual Studio 2022 17.4.3.
I'm using CFileDialog
to allow user to chose a file. By creating a new class derived from CFileDialog
, I am being notified whenever the user changes directories (folders).
I implemented this so I could control the filter applied to the list of files in the directory. However, I have been unsuccessful in this. Even if I don't change m_ofn
, I get an error.
Here is some sample code:
// Caller
#include "Browsing_test.h"
P brTest(true, NULL, NULL, 0, fileTypes);
brTest.BrowseTest();
// Browsing_test.h
class P : CFileDialog
{
public:
P(BOOL bOpenFileDialog,
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd *pParentWnd = NULL,
DWORD dwSize = 0,
BOOL bVistaStyle = TRUE) : CFileDialog(bOpenFileDialog,
lpszDefExt,
lpszFileName,
dwFlags,
lpszFilter,
pParentWnd,
dwSize,
bVistaStyle) {};
int BrowseTest(void);
#include "stdafx.h"
#include "Browsing_test.h"
int P::BrowseTest(void)
{
int resultDebug = (int)DoModal();
return resultDebug;
}
void P::OnFolderChange()
{
auto s = GetOFN(); // for modifying m_ofn member of the base class,
// but not used in this sample code
// Add modificatons to m_ofn here
ApplyOFNToShellDialog(); // Gets assert on updating flags
}
Running this code gives an error in dlgfile.cpp (Microsoft code) at line:
hr = (static_cast<IFileDialog*>(m_pIFileDialog))->SetOptions(dwFlags);
which returns hr = E_UNEXPECTED Catastrophic failure.
The value of dwFlags
was hex 40.
Upvotes: 0
Views: 131