【问题标题】:MFC CFileDialog prevent from opening *.ext.other_ext filesMFC CFileDialog 阻止打开 *.ext.other_ext 文件
【发布时间】:2012-03-24 16:02:32
【问题描述】:

我正在尝试使用以下代码创建文件对话框:

CFileDialog fd (TRUE, NULL, _T("*.pid"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY);

fd.m_ofn.lpstrInitialDir=m_CurrentDir;

if (fd.DoModal() == IDOK)
...

当对话框打开时,我会看到 *.pid 和 *.pid.saved 文件。
有没有什么可以阻止对话框显示 *.pid.saved 文件?

谢谢!

【问题讨论】:

    标签: mfc modal-dialog


    【解决方案1】:

    您必须指定对话框应该使用的过滤器:

    LPCTSTR szFilter = _T( "PID Files (*.pid)|*.pid|All Files (*.*)|*.*" );
    DWORD dwFlags =  OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    CFileDialog dlg( TRUE, _T( "pid" ), NULL, dwFlags, szFilter );  
    dlg.DoModal();
    ...
    

    【讨论】:

    • 谢谢 Eddie,你也让我开心。这很简单,但我挣扎了一段时间。
    猜你喜欢
    • 1970-01-01
    • 2013-11-01
    • 2023-03-07
    • 2015-12-16
    • 2013-02-01
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多