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

发布于 2024-10-08 14:30:11 字数 289 浏览 0 评论 0原文

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

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

重要的参数是第三个(lastPath)来进入特定目录! 在 Windows 7 中一切正常,但在 Windows 2000 中,只有当 LastPath (LPCTSTR lpszFileName) 为空时对话框才有效(否则对话框不会打开)

有什么想法吗?

感谢和问候 莱昂22

I develop with Visual Studio 2008 (Windows 7) and use

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

The important parameter is the third (lastPath) to get in a specific directory!
All works fine with Windows 7 but in Windows 2000 the Dialog only works if lastPath (LPCTSTR lpszFileName) is empty (otherwise the Dialog doesn't open)

Any ideas!?

Thanks and greets
leon22

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终陌 2024-10-15 14:30:11

好的,我发现了错误:

不要用 lpszFileName 设置初始目录!

正确用法:

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

问候 leon22

Ok, I have found the error:

don't set the initial directory with lpszFileName!

Right usage:

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

greets leon22

做个ˇ局外人 2024-10-15 14:30:11
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;
    }

}

As I debugged, CFolderPickerDialog can work find in win7/win10, but can only select file just like CFileDialog.
Above shows my workaround, I make user select a file ends with szFilter , and using CString::Left to get the correct folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文