How to get system image list icon index of an IShellItem?

前端 未结 2 1182
清歌不尽
清歌不尽 2021-02-02 02:11

Given a Windows Vista or newer IShellItem, how do i get the system image list icon index associated with that item?

For example (pseudo

2条回答
  •  情歌与酒
    2021-02-02 02:59

    In your great investigation you forget about IShellIcon interface. It available even in Windows XP.

    function GetIconIndex(AFolder: IShellFolder; AChild: PItemIDList): Integer; overload;
    var
      ShellIcon: IShellIcon;
      R: HRESULT;
    begin
      OleCheck(AFolder.QueryInterface(IShellIcon, ShellIcon));
      try
        R := ShellIcon.GetIconOf(AChild, 0, Result);
        case R of
          S_OK:;
          S_FALSE:
            Result := -1; // icon can not be obtained for this object
        else
          OleCheck(R);
        end;
      finally
        ShellIcon := nil;
      end;
    end;
    

提交回复
热议问题