2007. január 24., szerda

Extracting both the small and the large icon from a file


Problem/Question/Abstract:

Extracting both the small and the large icon from a file

Answer:

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
  // 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;

Nincsenek megjegyzések:

Megjegyzés küldése