procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
GetIcons(OpenDialog1.FileName);
end;procedure TForm1.GetIcons(const FileName: string);
var
index, iCount: integer;
icon: Ticon;
begin
index := -1;
iCount := ExtractIcon(Hinstance, Pchar(FileName), index);
Icon := TIcon.Create;
for index := 0 to iCount - 1 do
begin
Icon.Handle := ExtractIcon(Hinstance, Pchar(FileName), index);
ImageList1.AddIcon(Icon);
with ListView1.Items.Add do
begin
Caption := IntToStr(index + 1);
ImageIndex := ImageList1.Count - 1;
end;
end;
end;
begin
if OpenDialog1.Execute then
GetIcons(OpenDialog1.FileName);
end;procedure TForm1.GetIcons(const FileName: string);
var
index, iCount: integer;
icon: Ticon;
begin
index := -1;
iCount := ExtractIcon(Hinstance, Pchar(FileName), index);
Icon := TIcon.Create;
for index := 0 to iCount - 1 do
begin
Icon.Handle := ExtractIcon(Hinstance, Pchar(FileName), index);
ImageList1.AddIcon(Icon);
with ListView1.Items.Add do
begin
Caption := IntToStr(index + 1);
ImageIndex := ImageList1.Count - 1;
end;
end;
end;
OpenDialog1.Filter := '*.exe,*.dll,*.icl|*.exe;*.dll;*.icl';
ImageList1.Width := 32;
ImageList2.Height := 32;
ListView1.LargeImages := ImageList1;
还可以用 ExtractIconEX获得大小图标