新的 TFileOpenDialog 和旧的 TOpenDialog 有什么区别?

发布于 2024-11-13 17:02:44 字数 91 浏览 7 评论 0原文

新的 TFileOpenDialog 和旧的 TOpenDialog 有什么区别?
在我的计算机(Win 7/DXE)中,当我运行代码时,对话框看起来是一样的。

What is the difference between the new TFileOpenDialog and the old TOpenDialog?
In my computer (Win 7/DXE), when I run the code, the dialogs look the same.

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

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

发布评论

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

评论(2

十级心震 2024-11-20 17:02:44

当满足以下条件时,TOpenDialog 执行 TFileOpenDialog

  1. 程序在 Vista(及更高版本)下运行
  2. UseLatestCommonDialogs 为 true(这是默认值)
  3. 没有设置 OnIncludeItemOnCloseOnShow 事件

因此,当您仍在系统上使用 TOpenDialog 时,您可能最终会遇到这样的情况自动执行在大多数情况下,TFileOpenDialog,这解释了为什么它们对您来说看起来相同。

备注:TFileOpenDialog 不会退回到旧版 Windows 系统(XP 及以下) - 它只是引发异常。相反,TOpenDialog 会进行某种“向前跌倒”。

TOpenDialog executes TFileOpenDialog when the following conditions are met:

  1. the program is running under Vista (and up)
  2. UseLatestCommonDialogs is true (which is the default)
  3. no OnIncludeItem, OnClose or OnShow events are set

So while still using TOpenDialog on your system you may likely end up automagically executing TFileOpenDialog in most cases, which explains why they are looking the same for you.

Remark: TFileOpenDialog does not fall back on older Windows systems (XP and under) - it just raises an exception. On the opposite, TOpenDialog does some sort of "fall forward".

夜吻♂芭芘 2024-11-20 17:02:44
  • TOpenDialog 包装了传统的GetOpenFileName。它适用于所有版本的 Windows。
  • TFileOpenDialog 包装了 Vista 中引入的新的基于 COM 的对话框。因此它仅适用于 Vista 或更高版本。它比旧的对话框具有更多的功能,最显着的是与搜索的紧密集成。

Vista通用对话框
Vista 通用对话框

兼容性通用对话框
Compatibility commonDialog

如果调用,GetOpenFileName API 实际上会在大多数情况下生成新对话框正确,所以你实际上无法区分。也就是说,历史上 VCL 的 GetOpenFileName 包装器的实现并不精确,并且总是导致显示兼容性对话框。

那么新的 COM 对话框必须提供什么功能呢?

新对话框提供了更简单的自定义界面,但失去了一些通用性。如果您在 Vista 或更高版本上使用基于旧对话框模板的自定义与 GetOpenFileName,则对话框会降级为缺乏功能的丑陋兼容性版本。

新对话框的另一大优点是能够选择无限数量的文件。旧的 GetOpenFileName 接口在固定大小的缓冲区中返回多选文件名。这可能是一个真正的限制,在我自己的代码中,当我的应用程序在 XP 上运行时,我不得不修改 VCL 代码以使该缓冲区更大。

如果可能,TOpenDialog 会将工作委托给 TFileOpenDialog。它使用的测试要求满足以下所有条件:

  • 在 Windows Vista 或更高版本上运行。
  • Dialogs.UseLatestCommonDialogs 全局布尔变量为 true(默认为 true)。这允许您禁用新 COM 对话框的使用(如果您选择这样做)。
  • 未指定对话框模板。
  • OnIncludeItemOnCloseOnShow 事件均未分配。据推测,这些不能由 TFileOpenDialog 触发。

总结

如果您继续使用TOpenDialog,那么您将获得多选模式下无限数量的文件的好处。但是,如果您希望自定义对话框,并拥有新的对话框而不是丑陋的兼容性对话框,那么您需要执行以下操作:

  • 在 XP 上使用 TOpenDialog 和对话框模板方法。
  • 在 Vista 及更高版本上,使用 TFileOpenDialog 并使用 IFileDialogCustomize 实现自定义。
  • TOpenDialog wraps the traditional GetOpenFileName. It works on all versions of Windows.
  • TFileOpenDialog wraps the new COM based dialog that was introduced in Vista. It therefore only works on Vista or later. It has more functionality than the older dialogs, most notably the tight integration with search.

Vista common dialog
Vista common dialog

Compatibility common dialog
Compatibility common dialog

The GetOpenFileName API will in fact produce the new dialogs in most situations, if called correctly, so you can't actually tell the difference. That said, historically the VCL's wrapper for GetOpenFileName was implemented imprecisely and always resulted in the compatibility dialog being shown.

But what does the new COM dialog have to offer then?

The new dialog offers a much easier customisation interface at the loss of some generality. If you use the old dialog template based customisation with GetOpenFileName on Vista or later then the dialogs degrade to ugly compatibility versions that lack functionality.

The other big advantage of the new dialogs is the ability to select unlimited number of files. The old GetOpenFileName interface returned multi-select filenames in a fixed size buffer. This can be a real limitation and in my own code I have had to hack the VCL code to make this buffer larger for when my app runs on XP.

TOpenDialog will delegate the work to TFileOpenDialog if possible. The test it uses requires all of the following to be true:

  • Running on Windows Vista or later.
  • Dialogs.UseLatestCommonDialogs global boolean variable is true (default is true). This allows you to disable the use of the new COM dialog should you elect to do so.
  • No dialog template is specified.
  • OnIncludeItem, OnClose and OnShow events are all not assigned. Presumably these cannot be fired by TFileOpenDialog.

Summary

If you continue to use TOpenDialog then you will reap the benefit of unlimited number of file in multi-select mode. However, if you wish to customise the dialog, and have the new dialogs rather than the ugly compatibilty dialogs, then you need to do the following:

  • On XP use TOpenDialog and the dialog template method.
  • On Vista and later use TFileOpenDialog and implement customisation with IFileDialogCustomize.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文