Solved

How to get associated icon?

Posted on 1998-01-28
6
334 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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