0

在 Delphi 11 Alexandria 的 Windows 10 中的 32 位 VCL 应用程序中,我有一个TRzShellTree控件(来自 GetIt 中可用的 Konopka Signature VCL Controls 7.0 的 Ray Konopka):

object RzShellTree1: TRzShellTree
  Left = 0
  Top = 41
  Width = 201
  Height = 428
  Align = alLeft
  BaseFolder.Pidl = {
    004301000014001F50E04FD020EA3A6910A2D808002B30309D19002F433A5C00
    00000000000000000000000000000000000054003100000000003D5465581100
    44454C50484900003E0009000400EFBE1423F90E42549B502E00000000930F00
    000001000000000000000000000000000000DFED4800440045004C0050004800
    4900000016005A0031000000000042546956100053757065724D525500004200
    09000400EFBE2154F655425469562E000000210A000000004B00000000000000
    0000000000000000C43CDA00530075007000650072004D005200550000001800
    660031000000000042546F56100050524F4A45437E3100004E0009000400EFBE
    4254695642546F562E00000043EB0A0000000B00000000000000000000000000
    000008E22E00500052004F004A004500430054002000470052004F0055005000
    5300000018000000}
  Indent = 19
  ReadOnly = True
  SelectionPen.Color = clBtnShadow
  TabOrder = 0
  OnChange = RzShellTree1Change
  OnDragOver = RzShellTree1DragOver
end

...在TRzShellTree.OnAddItem事件处理程序中,我需要获取每个添加文件夹的 PATH:

procedure TformMain.RzShellTreeGroupsAddItem(Sender: TObject; ParentIShf: IShellFolder_NRC; ParentAbsIdList, ItemRelIdList: PItemIDList; Attribs: Integer; var AllowAdd: LongBool);
begin
  // How to get the PATH of the added folder?
end;

我认为这可以通过从ItemRelIdList: PItemIDList参数中提取路径来完成。但我不知道该怎么做。

4

2 回答 2

2

如果您需要完整路径,则将ParentAbsIdListItemRelIdList列表组合成一个新的绝对PItemIDList列表:

如何将相对 PIDL 转换为绝对 PIDL?

然后使用SHGetPathFromIDList().

或者,您可以使用原样ParentIShf.GetDisplayNameOf()传递它ItemRelIdList。如果您只指定SHGDN_FORPARSING标志,您将获得孩子的完整路径。如果您包含该SHGDN_INFOLDER标志,您将获得子项相对于其父项的路径。

RzShellUtils单元提供了使用PItemIDLists 的实用功能。例如, ConcatIdLists()(和ShellMemFree()) ShellGetPathFromIdList()、 和ShellGetFriendlyNameFromIdList()

Path := ShellGetFriendlyNameFromIdList(ParentIShf, ItemRelIdList, fnForParsing);
于 2022-02-02T21:11:15.597 回答
2

RzShellUtils 单元包含许多有用的函数来处理这类事情。尤其是,

uses
  RzShellUtils;

procedure TForm13.RzShellTree1AddItem(Sender: TObject; ParentIShf: IShellFolder_NRC; ParentAbsIdList,
  ItemRelIdList: PItemIDList; Attribs: Integer; var AllowAdd: LongBool);
var
  S: string;
begin
  S := ShellGetPathFromIdList( ItemRelIdList );
  CodeSite.Send( 'S', S );
end;
于 2022-02-03T06:20:42.810 回答