能不能在TreeView和ListView中使用资源管理器中的ImageList?(50分)

使用 ExtractAssociatedIcon函数得到ICON
再使用TImageList的AddIcon

Icon := TIcon.Create;
Icon.Handle := ExtractAssociatedIcon(HInstance, TempFile, 0);
ImageList1.AddIcon(Icon);

//tempfile可以是目录名

顺便提一个,如何在SpeedButton上 Draw Icon,
var
imgIcon: TIcon;
imgRect: TRect;
begin
imgIcon := TIcon.Create;
imgIcon.Handle := ExtractIcon( 'EXEFILENAME' );

with SpeedButton1.Glyph do begin
Width := imgIcon.Width;
Height := imgIcon.Height;
imgRect := Rect( 0, 0, Width, Height );
Canvas.CopyRect( imgRect, imgIcon.Canvas, imgRect );
end;
 
你说的AddIcon方法我知道。但要先判断文件类型,再去
注册表中找出指定的图标太慢。据说资源管理器是利用
Cache技术来加速的,我的意思是能不能直接取资源管理
器所使用的图标Cache。
 
资源管理其中的什么图标呢?
Listview不是已经提供所有文件类型的缺省图标了吗?
 
Listview提供缺省图标怎么设置?Treeview中也可以吗?
 
如果今晚大家还没搞到,我可以考虑在夜深人静时放到
ftp.lib.pku.edu.cn上去,那里应该够快了吧。
 
hei,dwwang 你喝醉了?
 
不好意思,怎么会把这个贴子贴到这里来?
应该是Delphi4 Patch#2那个问题。
 
需要用到ShellAPI,如果你有Delphi4,
可以看那个VirtualListView的例子。
 
怎么没反应了? 这应该是你想要的:

获取资源管理器中的ImageList:

function GetSystemImageList(Large: boolean): HImageList;
var
SFI: TSHFileInfo;
begin
// SHGetFileInfo puts the requested information in the SFI variable, but it
// also can return the handle of the system image list. We just pass an
// empty file because we aren't interested in it, only the returned handle.
if Large then
Result := SHGetFileInfo('', 0, SFI, SizeOf(SFI),
SHGFI_SYSICONINDEX or SHGFI_LARGEICON)
else
Result := SHGetFileInfo('', 0, SFI, SizeOf(SFI),
SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
end;

获取一个文件的imageindex;
function GetIconIndex(const APath: string; Attrs: DWORD): integer;
var
SFI: TSHFileInfo;
begin
if FileExists(APath) or DirectoryExists(APath) then
// If the file or directory exists, just let Windows figure out it's attrs.
SHGetFileInfo(PChar(APath), 0, SFI, SizeOf(TSHFileInfo),
SHGFI_SYSICONINDEX)
else
// File doesn't exist, so Windows doesn't know what to do with it. We have
// to tell it by passing the attributes we want, and specifying the
// SHGFI_USEFILEATTRIBUTES flag so that the function knows to use them.
SHGetFileInfo(PChar(APath), Attrs, SFI, SizeOf(TSHFileInfo),
SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES);
Result := SFI.iIcon;
end;
 
请斑竹给分:dwwang(40) jiangtao(10)
 
啊?就这还要扣掉我10分?
呜呜呜,不甘心...(做阿土仔状)
 
接受答案了.
 
顶部