2010-12-20 18 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)が空の場合のみダイアログが機能します(それ以外の場合はダイアログが開きません)

アイデア!?

おかげで、[OK]を leon22

答えて

0

を迎えて、私はエラーを発見した:

はlpszFileNameと初期ディレクトリを設定しないでください!

右用法:私はデバッグのよう

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

挨拶が

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; 
    } 

} 

をleon22、CFolderPickerDialogはwin7の/ win10で見つける作業することができますが、唯一のただのCFileDialogのようなファイルを選択することができます。 上記は私の回避策を示しています。私はユーザーがszFilterで終わるファイルを選択し、CString :: Leftを使って正しいフォルダを取得します。

関連する問題