{ note this demo extracts icons from files containing icons in the delphi 3 version the small icon extracted is displayed as a crappy looking larger icon in the image you cannot change the size of an icon without raising an exception and so this is a puzzle you might want to solve if you are still using delphi 3 and want to work with small icons} {http://www.awitness.org/delphi_pascal_tutorial/index.html} unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ShellApi, Dialogs, ExtCtrls, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Label1: TLabel; Label2: TLabel; OpenDialog1: TOpenDialog; Edit1: TEdit; Image1: TImage; Image2: TImage; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); Procedure GetFilesIcon(FileName:string); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); {Open File to find icons} begin If OpenDialog1.Execute then begin Edit1.Text := '-1'; GetFilesIcon(OpenDialog1.Filename); end; end; procedure TForm1.Button2Click(Sender: TObject); {get next icon} begin GetFilesIcon(OpenDialog1.FileName); end; Procedure TForm1.GetFilesIcon(FileName:string); var IconPos : Cardinal; NumIcons, PLargeIcon, PSmallIcon : HICON; begin try IconPos := StrToInt(Edit1.Text) + 1; {init -1 for pass 1} If FileExists(FileName) then begin Label1.Caption := 'Opened File : ' + FileName; {get total number of icons ExtractIconEx returns a small icon created even when only only one large icon actually exists in the file pass function -1 iconpos, and 0 0 for Var HIcons to signal function that it is to return the number of icons in the file} PLargeIcon := 0; PSmallIcon := 0; NumIcons := ExtractIconEx(PChar(FileName), -1, PLargeIcon, PSmallIcon, 1); If NumIcons = 0 then begin MessageDlg('No icons in this file' + chr(13) + 'Try finding extension in registry', mtError, [mbok],0); Label2.Caption := 'No Icons in this file'; end else begin Label2.Caption := 'TOTAL NUMBER OF ICONS IN FILE : ' + IntToStr(NumIcons); {did user put invalid integer into edit position box?} {note Iconpos starts at zero, NumIcons starts at 1} If IconPos > NumIcons then IconPos := NumIcons -1; If NumIcons = IconPos then IconPos := 0; {rollover count} {now get large, small icons at icon pos} ExtractIconEx(PChar(FileName), IconPos, PLargeIcon, PSmallIcon, 1); {if icon pic currently has handle then release resources first} If not (Image1.Picture.Icon.Empty) then Image1.Picture.Icon.ReleaseHandle; If not (Image2.Picture.Icon.Empty) then Image2.Picture.Icon.ReleaseHandle; Image1.Picture.Icon.Handle := PSmallIcon; Image2.Picture.Icon.Handle := PLargeIcon; {update edit box } Edit1.Text := IntToStr(IconPos); end; {num icons <> 0} end; {if fileexists} except {string did not convert to integer} MessageDlg('Enter a valid integer in the Edit Box!', mtError, [mbok], 0); end; {try} end; {procedure} procedure TForm1.FormCreate(Sender: TObject); begin Form1.Caption := 'Extract Icons'; Button1.Caption := 'Open file'; Button2.Caption := 'Next Icon'; Edit1.Text := '-1'; end; end.