CfileDialog不能依据选择的filter类型自动推导扩展名

来源:互联网 发布:运营数据分析 数据挖掘 编辑:程序博客网 时间:2024/06/06 00:48
原文地址:http://blog.sina.com.cn/s/blog_49366773010006f8.html

在使用CfileDialog发现CfileDialog不能依据选择的filter类型自动推导扩展名,总感觉这是一个缺陷。因为已经使用选择的filter进行文件类型筛选了。代码如下:

CString str("PDF Files (*.pdf)|*.pdf|PDF Edit Files (*.prj)|*.prj||");

CFileDialog dlg(FALSE, NULL, pDoc->getDocumentFileName(),

        OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, str, TheMainWnd());

使用dlg.GetFileExt()返回扩展名为空。

查询MSDN叙述如下:

lpszDefExt

The default filename extension. If the user does not include an extension in the Filename edit box, the extension specified by lpszDefExt is automatically appended to the filename. If this parameter is NULL, no file extension is appended.

但是也没有说明依据选择的filter添加扩展名。只是说明自动添加lpszDefExt。使用如下代码后dlg.GetFileExt()工作正常。

CString str("PDF Files (*.pdf)|*.pdf|PDF Edit Files (*.prj)|*.prj||");

CFileDialog dlg(FALSE, “.Pdf”, pDoc->getDocumentFileName(),

    OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, str, TheMainWnd());

即便选择了”.pfj”的文件dlg.GetFileExt()也工作正常。
0 0
原创粉丝点击