Reputation: 363
I inherited some code that is clearly based on this discussion:
cfiledialog and file extension
The code reads:
#define FILE_DIALOG_NAME cmb13
// CStarMaskDlg dialog
/* ------------------------------------------------------------------- */
class CSaveMaskDlg : public CFileDialog
{
DECLARE_DYNAMIC(CSaveMaskDlg)
//
// 9 December 2022 David C. Partridge
//
// I added OFN_EXPLORER to the open flags as per the note in the docs for CFileDialog::SetControlText
// that say:
// To use this method, you must create the dialog box with the OFN_EXPLORER style.
// Otherwise, the function will fail with an assertion.
//
public :
CSaveMaskDlg(bool bOpenFileDialog, // true for FileOpen, false for FileSaveAs
LPCTSTR lpszDefExt = nullptr,
LPCTSTR lpszFileName = nullptr,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER, // Add OFN_EXPLORER - see CFileDialog
LPCTSTR lpszFilter = nullptr,
CWnd* pParentWnd = nullptr):CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{
};
virtual ~CSaveMaskDlg()
{
};
protected:
virtual void OnTypeChange()
{
CFileDialog::OnTypeChange();
CString strFileName = GetFileTitle();
if (strFileName.GetLength())
{
if (m_ofn.nFilterIndex == 1)
strFileName += ".tif";
else
strFileName += ".fits";
SetControlText(FILE_DIALOG_NAME, strFileName);
};
};
};
IMPLEMENT_DYNAMIC(CSaveMaskDlg, CFileDialog)
/* ------------------------------------------------------------------- */
IMPLEMENT_DYNAMIC(CStarMaskDlg, CDialog)
The problem is that whenever SetControlText is invoked (at least on W10 and W11), an InvalidArgument exception is thrown.
As you can see I tried to fix the problem but so far it is beating me.
If this code is wrong, then please put me out of my misery and show me how it should go.
Thanks a lot David
Upvotes: 1
Views: 105