Solved

How to get associated icon?

Posted on 1998-01-28
6
329 Views
Last Modified: 2012-05-04
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?
0
Comment
Question by:MisterIQ
  • 4
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 150 total points
ID: 1357802
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
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357803
P.S.  Add ShellApi to uses clause.
0
 

Author Comment

by:MisterIQ
ID: 1357804
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357805
Hehe...  Delphi is good at many things, but providing good help is NOT one of them.

Cheers,
JB
0
 

Author Comment

by:MisterIQ
ID: 1357806
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
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357807
Yes, it will (should!) work on NT 4.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now