+ Reply to Thread
Results 1 to 2 of 2

Thread: Using CFileDialog to open a file in MFC

  1. #1

    Using CFileDialog to open a file in MFC

    Using CFileDialog to open a file in MFC

  2. #2
    You can use CFileDialog to Open or Save a file.

    Following is code snippet:

    Code:
    CString strFilter = _T("Text Files (*.txt)|*.txt|") ;
    
    CFileDialog objFileDialog(TRUE, ".txt", NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, strFilter) ;
    
    if (objFileDialog.DoModal() == IDOK)
    {
    	CString strPathName = objFileDialog.GetPathName() ;
    	CString strFileExt = objFileDialog.GetFileExt() ;
    	CString strFileName = objFileDialog.GetFileName() ;
    	CString strFileTitle = objFileDialog.GetFileTitle() ;
    }
    Note:
    OFN_PATHMUSTEXIST specify that specified file must exists. If it does not then CFileDialog will raise an exception.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts