[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

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
0
totok
Asked:
totok
1 Solution
 
DragonSlayerCommented:
ExtractIconEx will return an array of small icons and another array of large icons.
0
 
sundayboysCommented:
use SHGetFileInfo API,FLAG use SHGFI_ICON.that is ok.
0
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

  you can extract the small icon from any kind from files(exe, bmp,...) with this code,

uses shellapi;
procedure TForm1.Button1Click(Sender: TObject);
var
  Info : TSHFileInfo;
  InfoSize : Integer;
begin
  InfoSize := SizeOf(TSHFileInfo);
  FillChar(Info, InfoSize, 0);
  SHGetFileInfo(PChar('c:\aa.exe'), 0, Info, InfoSize, SHGFI_ICON or SHGFI_SMALLICON);
  Image1.Picture.icon.Handle := Info.hIcon;
end;
0
Industry Leaders: 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!

 
DragonSlayerCommented:
but that will only extract one icon... some EXEs come with more than one.
0
 
gemartiCommented:
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.


0
 
ntonyCommented:
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.
0
 
totokAuthor Commented:
Thank you, your code works great.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now