Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to get shell icon

I'm using this code for getting the shell icon (the one displayed in Windows Explorer).
Does anyone has an experience with a faster way to get these icons ? The SHGetFileInfo seems to be quite slow.

procedure TForm2.Button1Click(Sender: TObject);
var
  FileInfo: TSHFileInfo;
begin
  FillChar(FileInfo, SizeOf(FileInfo), 0);
  if SHGetFileInfo(PChar('c:\windows\'), 0, FileInfo, SizeOf(FileInfo),
    SHGFI_ICON or SHGFI_SMALLICON or SHGFI_SYSICONINDEX) <> 0 then 
    DrawIconEx(Canvas.Handle, 10, 10, FileInfo.hIcon, 0, 16, 16, 0, DI_IMAGE or 
      DI_MASK);
end;

Thanks!

like image 608
Martin Reiner Avatar asked Feb 10 '12 15:02

Martin Reiner


2 Answers

Try using the SHGFI_USEFILEATTRIBUTES flag as well. See the articles Tuning SHGetFileInfo for Optimum Performance and What does SHGFI_USEFILEATTRIBUTES mean? for more information.

like image 94
Garett Avatar answered Nov 01 '22 22:11

Garett


I have used a cache when I used SHGetFileInfo. Unless it is an .exe or .ico file (and perhaps a few more) the icon will be the same for the same file extension, so when you show a dir list you can use the same icon for files of the same type and you don't have to call (and wait for) SHGetFileInfo again.

like image 3
logicnet.dk Avatar answered Nov 02 '22 00:11

logicnet.dk