时间: 2021-07-31 作者:daque
在资源处置器中,每一个目次文献都有自已的图标,怎样在自已的运用步调里运用它呢?底下给出关系的例程,以及大略的挪用范例。uses shellapi;第一步 博得体例的图标列表的句柄,将之付与一个图像列表控件。procedure getsystemimagelist(imagelist:timagelist);var sysil: thandle; sfi: tshfileinfo;begin // 取小图标,即使将shgfi_smallicon替代成 //shgfi_largeicon则表白取大图标 sysil := shgetfileinfo('', 0, sfi, sizeof(sfi), shgfi_sysiconindex or shgfi_smallicon); if sysil <> 0 then begin //将imagelist的图像列表句柄指向体例图像句柄 imagelist.handle := sysil; //提防组件开释时开释图像句柄,很要害 imagelist.shareimages := true; end;end;第二步 博得要处置文献的图标索引//取一个文献的图标索引function geticonindex(const afile: string; attrs: dword): integer;//attrs不妨为表白文献或路途file_attribute_normal or file_attribute_directoryvar sfi: tshfileinfo; begin shgetfileinfo(pchar(afile), attrs, sfi, sizeof(tshfileinfo), shgfi_sysiconindex or shgfi_usefileattributes); result := sfi.iicon;end;范例挪用://如在treeview中获得c:\mydir的图标,由于是路途以是要加上路途的标记anode.imageindex := geticonindex('c:\mydir\', file_attribute_normal or file_attribute_directory);//如在treeview中获得c:\index.html的图标anode.imageindex := geticonindex('c:\index.html',file_attribute_normal);