Solved

How to get associated icon?

Posted on 1998-01-28
6
327 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

20 Experts available now in Live!

Get 1:1 Help Now