2010-12-20 50 views
0

我与Visual Studio 2008开发(Windows 7)中正常工作,并使用MFC的CFileDialog不要在Windows 2000

CFileDialog(TRUE, NULL, lastPath, NULL, szFilter); 

的重要参数是第三(lastPath)在一个特定的目录搞定! 所有工作正常与Windows 7,但在Windows 2000的对话框只有当lastPath(LPCTSTR lpszFileName)为空(否则对话框不打开)的作品

任何想法!?

感谢和问候 leon22

回答

0

好吧,我已经找到了错误:

不设置初始目录与lpszFileName!

右用法:

CFileDialog oDlg(TRUE, NULL, NULL, NULL, szFilter); 
oDlg.m_ofn.lpstrInitialDir = lastPath.GetBuffer(0); // set initial dir 

招呼leon22

0
CString szFilter = _T("hdc22_rx_keys_saved"); // 这样重加载文件类型时规避了异常 
CFolderPickerDialog objFileDlg(
     szFilter,/*LPCTSTR lpszFolder = NULL,*/ 
     OFN_READONLY,/*DWORD dwFlags = 0,*/ 
     NULL,/*CWnd* pParentWnd = NULL,*/ 
     0/*DWORD dwSize = 0*/ 
     ); 
if (objFileDlg.DoModal() == IDOK) 
{ 
    CString outputPath(objFileDlg.GetPathName()); 
    //CString outputPath(objFileDlg.GetFolderPath()); 
    if(!PathIsDirectory(outputPath)) 
    { 
     //for XP which CFolderPickerDialog cannot work 
     outputPath = outputPath.Left(outputPath.ReverseFind('\\')); 
    } 
    if(!PathIsDirectoryEmpty(outputPath)){ 
     //MessageBox(_T("请选择一个空的目录")); 
     _MSG_BOX_ERR(_T("[%s]不是一个存在的空目录"), outputPath); 
     return; 
    } 

} 

正如我调试,CFolderPickerDialog能找到工作,在Win7/win10,但只能选择文件一样的CFileDialog。 上面显示了我的解决方法,我让用户选择一个文件以szFilter结尾,并使用CString :: Left获取正确的文件夹。