Win32 实现 MFC CFileDialog 对话框

 1 void CWriteWnd::OpenFileDialog()
 2 {
 3     OPENFILENAME ofn;      
 4     TCHAR szFile[MAX_PATH] = _T("");
 5 
 6     ZeroMemory(&ofn, sizeof(ofn));  
 7     ofn.lStructSize = sizeof(ofn);
 8     ofn.hwndOwner   = *this;
 9     ofn.lpstrFile   = szFile;   
10     ofn.nMaxFile    = sizeof(szFile);  
11     ofn.lpstrFilter = NULL;
12     ofn.nFilterIndex    = 1;  
13     ofn.lpstrFileTitle  = NULL;  
14     ofn.nMaxFileTitle   = 0;  
15     ofn.lpstrInitialDir = NULL;  
16     ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
17 
18     GetOpenFileName(&ofn);//如果用户指定了一个文件名且点击OK按钮,返回值为非零值。如果用户取消或关闭Save对话框或错误出现,返回值为零。
19     if (GetOpenFileName(&ofn))  
20     {
21         //std::vector<wstring> vctString(1, szFile);//保存添加文件的路径
22     }
23    else
24    {
25        DWORD dwError = NOERROR;
26        dwError = CommDlgExtendedError();
27    }
28 }

注:The error codes returned by CommDlgExtendedError are defined in the Cderr.h file.

原文地址:https://www.cnblogs.com/chechen/p/3822356.html