PageRenderTime 5ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/VSTIcons_win.pas

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