Link to home
Start Free TrialLog in
Avatar of totok
totok

asked on

How I can get Small Icon from a file?

Hi,

Just a quick question: How I can get Small Icon from a file?

I am using delphi 5.

Thank you for your help
Avatar of DragonSlayer
DragonSlayer
Flag of Malaysia image

ExtractIconEx will return an array of small icons and another array of large icons.
Avatar of sundayboys
sundayboys

use SHGetFileInfo API,FLAG use SHGFI_ICON.that is ok.
ASKER CERTIFIED SOLUTION
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
but that will only extract one icon... some EXEs come with more than one.
Take a look:
I found a demo program with delphi 5 & 6 that will extract Icons & Bitmaps from exe's and dlls!

[DELPHI$]\Demos\ResXplor"

Source Code is included.


take a look at this (is more simple):



unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  comctrls, shellapi,extctrls;

type
  TForm1 = class(TForm)
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  SmallListView,BigListView:TListView;
  SmallImageList,BigImageList:TImageList;
implementation

{$R *.DFM}

procedure TForm1.FormActivate(Sender: TObject);
var
   IconBig,IconSmall:HICON;
   small,big:TIcon;
   Iconnr,nr:integer;
   hinst:THandle;
begin
     SmallImageList:=TImageList.Create(self);SmallImageList.Height:=16;SmallImageList.Width:=16;
     BigImageList:=TImageList.Create(self);BigImageList.Height:=32;BigImageList.Width:=32;

     SmallListView:=TListView.Create(self);
     SmallListView.Parent:=Self;
     SmallListView.Align:=alLeft;
     SmallListView.LargeImages:=SmallImageList;

     BigListView:=TListView.Create(self);
     BigListView.Parent:=Self;
     BigListView.Align:=alClient;
     BigListView.LargeImages:=BigImageList;

     small:=TIcon.Create;big:=TIcon.Create;

     IconNr:=-1;
     IconNr:=ExtractIconEx('c:\windows\explorer.exe',IconNr,IconBig,IconSmall,1);

     for nr:=0 to IconNr-1 do begin
         ExtractIconEx('c:\windows\explorer.exe',Nr,IconBig,IconSmall,1);
         small.Handle:=IconSmall;
         big.Handle:=IconBig;
         SmallImageList.AddIcon(small);BigImageList.AddIcon(big);
         SmallListView.Items.Add.ImageIndex:=nr;
         BigListView.Items.Add.ImageIndex:=nr;
     end;
end;

end.
Avatar of totok

ASKER

Thank you, your code works great.