Mega Code Archive

 
Categories / Delphi / Graphic
 

How to extract both the small and the large icon from a file

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,SHellapi; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var LargeIcon: HIcon; SmallIcon: HIcon; IconCount: Integer; i: Integer; FileName: PChar; begin // draw a stripe with all large icons contained in the file // and below of that a stripe with all small icons. FileName := 'C:\WinNT\RegEdit.exe'; IconCount := ExtractIconEx(FileName, -1, LargeIcon, SmallIcon, 0); for i := 0 to Pred(IconCount) do begin ExtractIconEx(FileName, i, LargeIcon, SmallIcon, 1); DrawIcon(Canvas.Handle, 5 + i * 36, 5, LargeIcon); DrawIconEx(Canvas.Handle, 5 + i * 36, 50, SmallIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL); end; end; end.