如何防止 IFileDialog 将通配符模式附加到文件类型描述中?

发布于 2024-11-09 02:28:23 字数 1377 浏览 4 评论 0原文

在新的 Windows 版本上(至少在 Windows 7 上是这样,但我有理由相信它会在 Vista 上发生)IFileDialog (因此 IFileOpenDialogIFileSaveDialog< /code>) 如果没有找到,会自动将通配符模式附加到文件类型描述中。

这是一个很好的功能,可以使使用更容易,同时增强指南的一致性和执行力。但有时这是不希望的。如果接受的扩展名很多(例如“所有图像”),则相应的组合框条目太长。最糟糕的是,这甚至没有记录,我只在 CodeProject 文章

在 Windows 7 上,向后兼容性检查(如 CodeProject 文章)不是那么强大,似乎手动附加到描述中的任何模式都会阻止自动附加。 另一个问题。然而这个解决方案远非理想。 (我决定再次问同样的问题,因为我相信 上一个 的标记和描述很差:(1)我首先通过查看由StackOverflow,我之前在 Google 中的查询没有找到它,并且(2)这个问题是普遍的并且不限于 Delphi。)

如何防止这种情况?

请注意,我必须使用 IFileDialog 因为我需要它提供的自定义功能。 (因此,不能切换到由 GetOpenFileNameGetSaveFileName 生成的对话框。)

On new Windows versions (it is so at least on Windows 7 but I have reasons to believe it happens on Vista to) IFileDialog (and thus IFileOpenDialog and IFileSaveDialog) automatically append the wildcard pattern to the file type description if they find none.

This is a nice feature to make usage easier while enhancing consistency and enforcement of guidelines. But sometimes it is not desired. If accepted extensions are numerous (like "All Images") then corresponding combobox entry is way too long. The worst thing is that this is not even documented and I only found a note about it (confirming my observations) at CodeProject article.

On Windows 7 the backward compatibility checking (as mentioned by CodeProject article) is not so strong and it seems any patterns manually appended to description will prevent automatic appending. This was already pointed out by an answer to another question. Yet this solution is far from ideal. (I decided to ask the same question again as I believe the previous one was poorly tagged and described: (1) I found it first by looking at similar questions suggested by StackOverflow, my previous queries in Google didn't found it and (2) the issue is general and not limited to Delphi.)

How to prevent this?

Note that I have to use IFileDialog because I need the customizations it offers. (So switching to dialog produced by GetOpenFileName and GetSaveFileName is not an option.)

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

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

发布评论

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

评论(1

若能看破又如何 2024-11-16 02:28:23

嗯,MSDN 提到了 IFileDialog。SetFilter Windows 7 已弃用。在这种情况下,我想您必须使用 IFileDialog。SetFileTypes 设置文件扩展名模式。正如您所说,通配符扩展已经存在,答案是使用这两个函数之一覆盖扩展模式。

由于缺少语言标签,没有示例代码。 SetFileTypes 的链接显示了一个很好的例子。

Well, MSDN mentions IFileDialog.SetFilter being deprecated for Windows 7. In that case I guess you have to use IFileDialog.SetFileTypes to set the file extension patterns. As you say that the wildcard extension is already there, the answer is to overwrite the extension patterns by using one of these two functions.

No sample code due to missing language tag. The link to SetFileTypes shows a pretty good example though.

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