MFC CFileDialog don';无法在Windows 2000中正常工作

MFC CFileDialog don';无法在Windows 2000中正常工作,mfc,directory,windows-2000,Mfc,Directory,Windows 2000,我使用Visual Studio 2008(Windows 7)开发并使用 重要的参数是在特定目录中获取的第三个(lastPath)! 所有这些都可以在Windows 7中正常工作,但在Windows 2000中,只有lastPath(LPCTSTR lpszFileName)为空时,该对话框才能工作(否则该对话框不会打开) 有什么想法吗 谢谢并问候 leon22好的,我发现了错误: 不要用lpszFileName设置初始目录 正确用法: CFileDialog oDlg(TRUE, NULL,

我使用Visual Studio 2008(Windows 7)开发并使用

重要的参数是在特定目录中获取的第三个(lastPath)! 所有这些都可以在Windows 7中正常工作,但在Windows 2000中,只有lastPath(LPCTSTR lpszFileName)为空时,该对话框才能工作(否则该对话框不会打开)

有什么想法吗

谢谢并问候
leon22

好的,我发现了错误:

不要用lpszFileName设置初始目录

正确用法:

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

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获得正确的文件夹

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

}