
Change file index filter of the standard file open/save dialog
Quote:
> Thanks!
> But how (where) can I insert this code (to)?
> Could you please show me how to insert
> this code in my SDI application? Sorry beginner.
Hi Nassau,
By default the file open command is handled by CWinApp::OnFileOpen.
What you can do is add your own message handler for the file open
command and display the file open dialog yourself, with the filtering
you want.
BEGIN_MESSAGE_MAP(CPlainSDIApp, CWinApp)
//{{AFX_MSG_MAP(CPlainSDIApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen) // ADDED
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
// ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) // REMOVED
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
I commented out the default OnFileOpen line and the wizard added the
ADDED line when I added a message handler for ID_FILE_OPEN. So now the
menu command will come to your own OnFileOpen. It should look something
like this:
void CPlainSDIApp::OnFileOpen()
{
CFileDialog dlg(true);
dlg.m_ofn.lpstrFilter = TEXT("Text
Files\0*.TXT\0Assembly\0*.asm\0Cpp\0*.cpp\0\0");
dlg.m_ofn.nFilterIndex = 2;
if (dlg.DoModal() == IDOK)
OpenDocumentFile(dlg.GetPathName());
Quote:
}
--
Scott McPhillips [VC++ MVP]