不妨试一下: uses ShellApi; procedure TForm1.Button1Click(Sender: TObject); var FileInfo: TSHFileInfo; begin if OpenDialog1.Execute then begin FileInfo.iIcon := 0; SHGetFileInfo(PChar(OpenDialog1.FileName), 0, FileInfo, SizeOf(TSHFileInfo),SHGFI_ICON or SHGFI_SMALLICON); Image1.picture.Icon.Handle := FileInfo.hIcon; end; end;
uses ShellApi;
procedure TForm1.Button1Click(Sender: TObject);
var
FileInfo: TSHFileInfo;
begin
if OpenDialog1.Execute then
begin
FileInfo.iIcon := 0;
SHGetFileInfo(PChar(OpenDialog1.FileName), 0, FileInfo, SizeOf(TSHFileInfo),SHGFI_ICON or SHGFI_SMALLICON);
Image1.picture.Icon.Handle := FileInfo.hIcon;
end;
end;
建议:
Icon:ticon;
filename:string;//你的文件
SHGetFileInfo(PChar(FileName), 0, FileInfo, SizeOf(TSHFileInfo),
SHGFI_ICON or SHGFI_LARGEICON);
Icon := TIcon.Create;
Icon.Handle:=FileInfo.hIcon;
Icon.SavetoFile('d:\ee.ico');