//from
http://www.csdn.net/expert/Topic/409/409823.shtm
回复人: taxi(游少爷) (2001-12-8 10:20:29) 得20分
procedure TfrmMain.ExtractFileIcon(Filename:string);
var
count,index,i:integer;
j:word;
ext:string;
begin
try
if inifile.ReadInteger('ExtractStyle','Option',0)=0 then
lvIcons.Items.BeginUpdate;
ext:=LowerCase(ExtractFileExt(Filename));
if (ext='.exe') or (ext='.dll') or (ext='.icl') then
begin
index:=-1;
count:=ExtractIcon(Hinstance,Pchar(Filename),index);
ProgressBar1.Max:=count;
for i:=0 to count-1 do
begin
ProgressBar1.Position:=i+1;
inc(FIconCount);
SetLength(FIcons,FIconCount);
FIcons[FIconCount-1]:=TIcon.Create;
FIcons[FIconCount-1].Handle:=ExtractIcon(Hinstance,Pchar(Filename),i);
Icons.AddIcon(FIcons[FIconCount-1]);
Image1.Picture.Icon:=FIcons[FIconCount-1];
Application.ProcessMessages;
with lvIcons do
begin
Items.Add;
Items[Items.Count-1].Caption:=ExtractFileName(FileName)+'['+
IntToStr(i+1)+']';
Items[Items.Count-1].ImageIndex:=Items.Count-1;
end;
end;
ProgressBar1.Position:=0;
end
else
begin
j:=0;
inc(FIconCount);
SetLength(FIcons,FIconCount);
FIcons[FIconCount-1]:=TIcon.Create;
FIcons[FIconCount-1].Handle:=ExtractAssociatedIcon(Hinstance,Pchar(Filename),j);
Icons.AddIcon(Ficons[FIconCount-1]);
Image1.Picture.Icon:=FIcons[FIconCount-1];
Application.ProcessMessages;
with lvIcons do
begin
Items.Add;
Items[Items.Count-1].Caption:=ExtractFileName(Filename);
Items[Items.Count-1].ImageIndex:=Items.Count-1;
end;
end;
if inifile.ReadInteger('ExtractStyle','Option',0)=0 then
lvIcons.Items.EndUpdate;
index:=0;
Image1.Picture.Icon.Handle:=ExtractIcon(Hinstance,Pchar(Application.Exename),index);
except
ShowMessage('我kao,发生错误了:(');
end;
end;