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

时间:2012-10-31 11:58:17

标签: delphi winapi

我想使用SHGetFileInfo来获取Windows控制面板图标,我使用Shell来获取Windows控制面板 代码:

var
  psfDeskTop: IShellFolder;
  psfWork: IShellFolder;

  pidworkDir: PITEMIDLIST;
  pidChild: PITEMIDLIST;

  pEnumList: IEnumIDList;
  celtFetched: ULONG;
  //chEaten, dwAttributes: ULONG;
  FileInfo: SHFILEINFOW;

  //conGUID: string;
  StrRetName: TStrRet;
  Name: PChar;

begin

  SHGetDesktopFolder(psfDeskTop);
  SHGetSpecialFolderLocation(0, CSIDL_CONTROLS, pidworkDir);
  psfDeskTop.BindToObject(pidworkDir, nil, IID_IShellFolder, psfWork);
  psfWork.EnumObjects(0, SHCONTF_NONFOLDERS or SHCONTF_FOLDERS or SHCONTF_INCLUDEHIDDEN, pEnumList);

  while pEnumList.Next(1, pidChild, celtFetched) = 0 do
  begin

    //here I want to use SHGetFileInfo to get file icon
    //but , SHGetFileInfo need a absolute PIDL,IEnumIDList enumerates relative PIDL

  end  

end;

我在MSDN中找到了一个名为ILCombine的函数来做到这一点,但我在Delphi中找不到,我想知道是否有可能将pidworkDir和pidChild结合起来在Delphi中获得绝对的PIDL?

或者还有其他方法可以获取文件的图标吗?

1 个答案:

答案 0 :(得分:3)

你确实可以从Delphi调用ILCombine。您需要使用ShlObj单位。

uses
  ShlObj;
....
pidItemAbsolute = ILCombine(pidworkDir, pidChild);

如果您的Delphi没有声明ILCombine,那么您可以像这样导入它:

function ILCombine(pidl1, pidl2: PItemIDList): PItemIDList; 
    stdcall; external 'shell32.dll';