如何在打开对话框中设置排序模式

发布于 2024-09-03 20:28:24 字数 136 浏览 10 评论 0原文

用户可以通过单击相应的列标题,在标准 Windows 打开对话框(“详细信息”视图模式)中按名称、日期或大小手动对文件进行排序。如何在应用程序中以编程方式在打开对话框(Delphi 中的 TOpenDialog 类)中设置排序模式,以便对话框以首选排序打开?

A user can manually sort files in a standard Windows Open Dialog (in "Details" view mode) by Name, Date or Size by clicking on the corresponding column header. How to set a sorting mode in Open Dialog (TOpenDialog class in Delphi) programmatically in application so that the dialog opens with a preferred sorting?

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

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

发布评论

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

评论(4

云之铃。 2024-09-10 20:28:24

TFileOpenDialog (D2009) 在内部使用 Windows 的 IFileDialog 接口。该界面不提供任何设置文件排序的方法。但是它确实有 SetClientGuid 和 ClearClientData。 TFileOpenDialog 通过其 ClientGUID 属性使用它们。为您的特定实例设置 ClientGuid 指示窗口保留对话框的状态。 Windows 将记住最后打开的文件夹、文件的列出方式和排序方式。

因此,如果您只是想通过记住用户在打开文件时设置对话框的最后方式来适应用户,那么您所要做的就是设置 FileOpenDialog 的 ClientGUID。

要获取 GUID,请在代码编辑器中按 Ctrl-Shft-G。只需记住在将其粘贴到 ClientGUID 属性中时不要使用方括号。

TFileOpenDialog (D2009) internally uses the IFileDialog interface from Windows. That interface doesn't offer any way in which to set the sorting of the files. However it does have SetClientGuid and ClearClientData. These are used by TFileOpenDialog through its ClientGUID property. Setting a ClientGuid for your particular instance instructs windows to persist the dialog's state. Windows will then remember things as the last folder opened, the way the files are listed and the sorting.

So, if you just want to accommodate your users by remembering the last way they had the dialog set up when opening a file, all you have to do is set the ClientGUID of the FileOpenDialog.

To get a GUID, press Ctrl-Shft-G in the code editor. Just remember to leave off the square brackets when pasting this into the ClientGUID property.

你的呼吸 2024-09-10 20:28:24

GetOpenFileName() API 和 Vista IFileDialog 接口对此不支持。您可以按照本杂志文章中的演示破解该对话框。请注意,这篇文章已经过时了。而且像这样的黑客攻击很脆弱,他们很可能会在下一版本的 Windows 上停止工作。

The GetOpenFileName() API and the Vista IFileDialog interface have no support for this. You can hack the dialog as demonstrated in this magazine article. Beware that the article is quite dated. And that hacks like these are brittle, they may well stop working on the next version of Windows.

┈┾☆殇 2024-09-10 20:28:24

您可以使用 DexExpress 的 TcxShellListView 之类的组件来推出自己的组件。它允许对文件进行排序。

You could roll your own using a component like DexExpress' TcxShellListView. It allows for sorting of files.

蓝天白云 2024-09-10 20:28:24

在谷歌搜索主题后,我发现了一些“神奇数字”,并得出以下解决方案(TOpenDialog.OnFolderChange事件处理程序):

procedure TDM.OpenDlgFolderChange(Sender: TObject);
const
  FCIDM_SHVIEW_LARGEICON = $7029;
  FCIDM_SHVIEW_SMALLICON = $702A;
  FCIDM_SHVIEW_LIST = $702B;
  FCIDM_SHVIEW_REPORT = $702C;
  FCIDM_SHVIEW_THUMBNAIL = $702D;
  FCIDM_SHVIEW_TILE = $702E;

  ByName = $7602;
  BySize = $7603;
  ByType = $7604;
  ByModified = $7605;
  ByAttributes = $7608;

var
  Handle: THandle;

begin
  Handle:= FindWindowEx(GetParent(OpenDlg.Handle), 0, 'SHELLDLL_DefView', nil);
  SendMessage(Handle, WM_COMMAND, FCIDM_SHVIEW_REPORT, 0);
  SendMessage(Handle, WM_COMMAND, ByAttributes, 0);
  SendMessage(Handle, WM_COMMAND, ByName, 0);
end;

第一条消息设置“详细信息”视图模式,第二条设置“按属性”排序,第三条“按名称”排序;需要两个不同的“排序”消息来保证最终排序是升序的。

上面的代码在Win XP上运行良好,但排序部分在Win 2000 SP4上不起作用;在 Win 7 上,“排序幻数”发生了变化,即“ByName = $7603”等。

After googling the subject I found some "magic numbers" and have come to the following solution (TOpenDialog.OnFolderChange event handler):

procedure TDM.OpenDlgFolderChange(Sender: TObject);
const
  FCIDM_SHVIEW_LARGEICON = $7029;
  FCIDM_SHVIEW_SMALLICON = $702A;
  FCIDM_SHVIEW_LIST = $702B;
  FCIDM_SHVIEW_REPORT = $702C;
  FCIDM_SHVIEW_THUMBNAIL = $702D;
  FCIDM_SHVIEW_TILE = $702E;

  ByName = $7602;
  BySize = $7603;
  ByType = $7604;
  ByModified = $7605;
  ByAttributes = $7608;

var
  Handle: THandle;

begin
  Handle:= FindWindowEx(GetParent(OpenDlg.Handle), 0, 'SHELLDLL_DefView', nil);
  SendMessage(Handle, WM_COMMAND, FCIDM_SHVIEW_REPORT, 0);
  SendMessage(Handle, WM_COMMAND, ByAttributes, 0);
  SendMessage(Handle, WM_COMMAND, ByName, 0);
end;

First message sets "Details" view mode, the second sets sorting "By Attributes" and the third "By Name"; the two different 'sorting' messages are required two guaranty that the final sorting is ascending.

The above code works fine on Win XP, but the sorting part does not work on Win 2000 SP4; on Win 7 the "sorting magic numbers" are shifted, i.e. "ByName = $7603", etc.

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