Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Extracting both the small and the large icon from a file
This article has not been rated yet. After reading, feel free to leave comments and rate it.
The Windows help files only document ExtractIcon which extracts the large icon from an EXE (DLL, etc.).
There is an undocumented function ExtractIconEx which retrieves both the small and the large icon as shown below.
 | |  | | procedure TForm1.FormPaint(Sender: TObject);
var
LargeIcon: HIcon;
SmallIcon: HIcon;
IconCount: Integer;
i: Integer;
FileName: PChar;
begin
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;
| |  | |  |
Comments:
|