Home Search Contact us About us
Title Using CFileDialog
Summary Common file dialog boxes provide an easy way to implement File Open and File Save As dialog boxes (as well as other file-selection dialog boxes) in a manner consistent with Windows standards.
Contributor John McTainsh
Published 13-Oct-2000
Last updated 13-Oct-2000
Page rating   90% for 15 votes Useless Brilliant

Description.

Common file dialog boxes provide an easy way to implement File Open and File Save As dialog boxes (as well as other file-selection dialog boxes) in a manner consistent with Windows standards.

How to use it.

The following code displays the standard windows file dialog. In a standard MFC application it is not usually necessary to #include <afxdlgs.h>. But if problems occur try it.
    //
    //Call the Dialog
    //
    static char szFilter[] = _T("Text (*.txt)|*.txt|")
                             _T("Database Files (*.mdb)|*.mdb|")
                             _T("All Files (*.*)|*.*||");
    CFileDialog fd( 
            true, 
            NULL, 
            _T("Wally"), 
            OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
            szFilter, 
            this );
    fd.m_ofn.lpstrInitialDir = _T("C:\\Temp");
    if( fd.DoModal() == IDOK )
    {
        MessageBox( fd.GetPathName(),
                    _T("File Name"), MB_ICONINFORMATION );
    }
Comments Date
Home Search Contact us About us