?
Solved

How to get associated icon?

Posted on 1998-01-28
6
Medium Priority
?
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 600 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

800 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