/VSTIcons_win.pas

http://github.com/foxblock/PNDTools · Pascal · 39 lines · 28 code · 7 blank · 4 comment · 2 complexity · 31679f5d417a201873646542192d3490 MD5 · raw file

  1. unit VSTIcons_win;
  2. interface
  3. uses ShellAPI, Controls;
  4. { Loads a pointer to the system icons into the passed ImageList
  5. No image is actually added until requested by GetIconIndex }
  6. procedure LoadSystemIcons(Target : TImageList);
  7. { Loads the fileicon for the passed file from the system icon-list and returns
  8. an image index for any associated ImageList }
  9. function GetIconIndex(const Filename : String; const Open : Boolean) : Integer;
  10. implementation
  11. procedure LoadSystemIcons(Target : TImageList);
  12. var
  13. SFI : TSHFileInfo;
  14. begin
  15. Target.Handle := SHGetFileInfo('', 0, SFI, SizeOf(SFI),
  16. SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
  17. Target.ShareImages := True;
  18. end;
  19. function GetIconIndex(const Filename : String; const Open : Boolean) : Integer;
  20. var
  21. SFI : TSHFileInfo;
  22. Flags : Cardinal;
  23. begin
  24. Flags := SHGFI_SYSICONINDEX or SHGFI_SMALLICON;
  25. if Open then
  26. Flags := Flags or SHGFI_OPENICON;
  27. if SHGetFileInfo(PChar(Filename), 0, SFI, SizeOf(TSHFileInfo), Flags) = 0 then
  28. Result := -1
  29. else
  30. Result := SFI.iIcon;
  31. end;
  32. end.