Solved

developing a file explorer

Posted on 1998-01-28
8
158 Views
Last Modified: 2010-04-04
While developing an file explorer I have problems extracting the small icon of the associated executable file.

The large on wasn't difficult: You only have to use the api call EXTRACTASSOCIATEDICON and you will get an iconhandle. The system metrics define the size of the returned icon. This ist 32x32 with normal screen resolution.

Thanks

Marc
0
Comment
Question by:M_Hoeper
  • 4
  • 2
  • 2
8 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357712
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: 1357713
P.S.  Add ShellApi to uses clause.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357714
Doesn't this works :

uses ShellApi;

procedure TForm1.Button1Click(Sender: TObject);
var
  IconIndex : word;
  h : hIcon;
begin
  IconIndex := 0;
  h :=
    ExtractAssociatedIcon(hInstance,
                        'C:\WINDOWS\NOTEPAD.EXE',
                         IconINdex);

  DrawIcon(Form1.Canvas.Handle,
             10,
             10,
             h);

Zif.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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 8

Expert Comment

by:ZifNab
ID: 1357715
Sorry, had a little delay. Didn't saw answer of JimBob.
0
 

Author Comment

by:M_Hoeper
ID: 1357716
Thanks for your answer.

SHGetFileInfo doesn't work with Windows NT (4) but my program have to run with NT.

I'm sorry that I didn't write it in my question.
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1357717
ShGetFileInfo does work on NT 4 (but not 3.51).  I have just run a sample app on an NT 4 machine, and it didn't work 1st time.  Then (without changing any code!!) I recompiled it, and ran it again and it worked...  That is very odd.

The 1st time it didn't work, it didn't even add it to the image list (imgLarge.Count = 0).  Maybe it didn't get a valid icon handle back.  Unfortunately, I can't go back and check because every time I run it now it works fine...

JB
0
 

Author Comment

by:M_Hoeper
ID: 1357718
Oh, sorry. I looked into the help file of dephi3. They write that the SHGetFileInfo routine only works with win95.

Now, i tried a sample code and it works wonderfull... And I'm a bit confused.

Please answer the question again and you will get the 200 points.

I send the question to the windows experts, too. And they recommend to use the ExtractIconEx routine :-) This routine isn't included in the delphi help, but is integrated in the shellapi unit.

Thanks

Marc
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 200 total points
ID: 1357719
You can use ExtractIconEx, but you need the name of the file that has the icon, which must be EXE, DLL or ICO.  With ShGetFileInfo, you can pass it ANY file (e.g. DOC), and it will return the associated icon.
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

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 65
creating threads in delphi 1 137
Create a path if not exists 7 92
how to make 2 step back? ..\..\ ExtractFilePath (paramstr(0)) 5 53
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

820 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