如何获取指定文件的图标并显示在toolbutton里啊???(20分)

  • 主题发起人 egetrich
  • 开始时间
E

egetrich

Unregistered / Unconfirmed
GUEST, unregistred user!
var
FileName:string;
FileInfo:_SHFILEINFOA ;
Icon:TICon;
begin
if self.OpenDialog1.Execute then
begin
Icon:=TICon.Create;
SHGetFileInfo(PChar(FileName),0,FileInfo,SizeOf(FileInfo),SHGFI_ICON);
ICon.Handle:=FileInfo.hIcon ;
self.imglstCustom.InsertIcon(0,icon);
self.ToolButton1.ImageIndex:=0;
Icon.Free ;
end;
end;

------------------我采用以上程序 总是得到一个文件夹的图标,参数换成SHGFI_SMALLICON 又什么都没有.请高手帮忙啊
 
uses shellapi;
var
FileName:string;
sinfo: SHFILEINFO;
Icon:TICon;
begin
if OpenDialog1.Execute then begin
FileName:=OpenDialog1.FileName;
ZeroMemory(@sinfo, sizeof(sinfo));
SHGetFileInfo(PChar(FileName), FILE_ATTRIBUTE_NORMAL,
sinfo, sizeof(sinfo), SHGFI_USEFILEATTRIBUTES or SHGFI_ICON);
Image1.Picture.Icon.Handle := sinfo.hIcon;
Icon:=TICon.Create;
ICon.Handle:=sinfo.hIcon ;
self.imglstCustom.InsertIcon(0,icon);
self.ToolButton1.ImageIndex:=0;
end;
end;
 
顶部