如何取得进程图标,并放入Tlistview中(50分)

  • 主题发起人 主题发起人 dage111
  • 开始时间 开始时间
D

dage111

Unregistered / Unconfirmed
GUEST, unregistred user!
如何取得文件图标,并放入Tlistview中?
有谁能提供解决方法或者谁能提供这个第三方控件atshell?

如该问题
http://www.delphibbs.com/delphibbs/dispq.asp?lid=452967
一样

谁能提供这个第三方控件atshell?
 
uses
ShellAPI;

var
IconList:TStringList;

procedure ListView_SetItemImageIndex(Item: TListItem);
var
nIndex:Integer;
Icon:TIcon;
fileName:string;
extName:string;
sinfo:SHFILEINFO;
begin
if TListView(Item.ListView).SmallImages<>nil then
begin
fileName:=Item.Caption;
extName:=ExtractFileExt(fileName);
nIndex:=IconList.IndexOf(extName);
if nIndex>-1 then
begin
nIndex:=Integer(IconList.Objects[nIndex]);
Item.ImageIndex:=nIndex;
end else
begin
FillChar(sinfo, SizeOf(sinfo),0);
SHGetFileInfo(PChar(extName),FILE_ATTRIBUTE_NORMAL,sinfo,SizeOf(sInfo),SHGFI_USEFILEATTRIBUTES or SHGFI_ICON or SHGFI_SMALLICON);
if sinfo.hIcon>0 then
begin
Icon:=TIcon.Create;
Icon.Handle:=sinfo.hIcon;
nIndex:=TListView(Item.ListView).SmallImages.AddIcon(Icon);
Item.ImageIndex:=nIndex;
IconList.AddObject(extName,TObject(nIndex));
end;
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Item:TListItem;
begin
Item:=ListView1.Items.Add;
Item.Caption:='c:/test.jpg';
ListView_SetItemImageIndex(Item);
end;

initialization
IconList:=TStringList.Create;
finalization
IconList.Free;

end.
 
IconNum := ExtractIcon(hInstance, PChar(FileName), UINT(-1));
if IconNum > 0 then
begin
Icon := TIcon.Create;
Icon.Handle := ExtractIcon(hInstance, PChar(FileName), 0);
Sysmnuil.AddIcon(Icon);
Inc(IconTotalNum);
itm.ImageIndex := IconTotalNum - 1;
Icon.ReleaseHandle;
end
搞定
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部