Ragesh Chakkadath
Ragesh Chakkadath

Reputation: 1531

Customizing CFileDialog error messages

It would be nice if there is a way to customize the CFileDialog error messages.

For example, Entering an invalid drive in the File name edit box causes an error message like below.

Invalid Drive

I want to show a different error here. Is it possible without subclassing CFileDialog?

It is also fine if the dialog returns instead of showing error.

Here is the code snippet:

CFileDialog dlgFile( TRUE, 0, 0,  OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilters, 0, 0, 0 );
dlgFile.m_ofn.FlagsEx |= OFN_EX_NOPLACESBAR;
dlgFile.m_ofn.lpstrTitle= csTitle;
dlgFile.m_ofn.lpstrInitialDir = NULL;

const int nMaxFiles = 2512;
const int nBuffSize = ( ( nMaxFiles * ( MAX_PATH + 1 ) ) + 1 ) * sizeof( TCHAR );
dlgFile.GetOFN().lpstrFile = new TCHAR[ nBuffSize ];
::ZeroMemory( dlgFile.GetOFN().lpstrFile, nBuffSize );
dlgFile.GetOFN().nMaxFile = nBuffSize;
if( dlgFile.DoModal() == IDOK )
{
   ...
   ...
}

Upvotes: 1

Views: 974

Answers (2)

Ragesh Chakkadath
Ragesh Chakkadath

Reputation: 1531

Just found out that setting OFN_NOVALIDATE to m_ofn.Flags removes this validation and returns from the dialog without showing that warning.

Upvotes: 0

cprogrammer
cprogrammer

Reputation: 5675

if it's ok just to modify the dialog, you can install a hook SetWindowsHookEx with WH_CBT.

Upvotes: 2

Related Questions