How to get associated icon?

Dear experts,

I have to find the associated icon for a file, but I need it in different sizes. Using the ExtractAssociatedIcon function I get an icon handle, but neither the path nor the index are returned (as it should be according to the help) unless the file does not exist (in this case I get 'shell32.dll' as path and 1 as index).
The icon handle I get this way is of no use for me because the icon is of standard size. To get a smaller icon I could use the LoadImage function, but it needs the identifier which I don't know.
Can anybody tell me how it works?
MisterIQAsked:
Who is Participating?
 
JimBob091197Connect With a Mentor Commented:
Hi

I answered a similar question a few days ago.  Here is the answer:


----
Hi

You can use ShGetFileInfo to get large & small icon (and other stuff too).

E.g.
var
shfi: TShFileInfo;
Ico: TIcon;
Filename: string;
begin
Filename := 'C:\Autoexec.bat';

// Get normal (32*32) icon.
FillChar(shfi, SizeOf(TShFileInfo), 0);
ShGetFileInfo(PChar(Filename), 0, shfi, SizeOf(TShFileInfo), SHGFI_ICON);
Ico := TIcon.Create;
Ico.Handle := shfi.hIcon;

// Do something with icon, e.g. add to 32*32 TImageList:
//imgLarge.AddIcon(Ico);

Ico.Free;

// Get small (16*16) icon.
FillChar(shfi, SizeOf(TShFileInfo), 0);
ShGetFileInfo(PChar(Filename), 0, shfi, SizeOf(TShFileInfo), SHGFI_ICON or SHGFI_SMALLICON);
Ico := TIcon.Create;
Ico.Handle := shfi.hIcon;

// Do something with icon, e.g. add to 16*16 TImageList:
//imgSmall.AddIcon(Ico);

Ico.Free;



Regards,
JB  
 
----
0
 
JimBob091197Commented:
P.S.  Add ShellApi to uses clause.
0
 
MisterIQAuthor Commented:
Thanks a lot!
I was sure that there existed a function that does exactly what I want!! Why is it impossible to find any hints in the online help?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
JimBob091197Commented:
Hehe...  Delphi is good at many things, but providing good help is NOT one of them.

Cheers,
JB
0
 
MisterIQAuthor Commented:
I forgot to ask: Does it work with Windows NT? I am using Win95, but the programs I write have to run on Windows NT.
0
 
JimBob091197Commented:
Yes, it will (should!) work on NT 4.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.