//设置TreeView或ListView的Images,可以是Small或Large<br>procedure TForm1.SetImageLists;<br>begin<br> //向ListView传递系统的ImageList<br> with ListView1 do<br> begin<br><br> if not Assigned(SmallImages) then<br> begin<br> SmallImages := TImageList.Create(Self);<br> SmallImages.ShareImages := True;<br> SmallImages.Handle := SHGetFileInfo('c:/',<br> 0,<br> FileInfo,<br> SizeOf(FileInfo),<br> SHGFI_SMALLICON or SHGFI_SYSICONINDEX or SHGFI_TYPENAME or SHGFI_USEFILEATTRIBUTES);<br> end;<br> if not Assigned(LargeImages) then<br> begin<br> LargeImages := TImageList.Create(Self);<br> LargeImages.ShareImages := True;<br> LargeImages.Handle := SHGetFileInfo('c:/',<br> 0,<br> FileInfo,<br> SizeOf(FileInfo),<br> SHGFI_LARGEICON or SHGFI_SYSICONINDEX or SHGFI_TYPENAME or SHGFI_USEFILEATTRIBUTES);<br> end;<br><br> end;<br>end;<br><br>//Tree或ListView的GetImageIndex时调用此代码,把文件名传进去,返回的就是ImageIndex了<br>//Large表示返回的是否大图标的Index,跟上面的设置应保持一致<br>function TForm1.GetFileIconIndex(FileName: string; Large: Boolean): Integer;<br>{ 获取图标的序号函数 }<br>var<br> Ext: string;<br> Flags: Integer;<br>begin<br> Ext := FileName;<br> Flags := SHGFI_SYSICONINDEX or SHGFI_TYPENAME or SHGFI_USEFILEATTRIBUTES;<br> if Large then<br> Flags := Flags or SHGFI_LARGEICON<br> else<br> Flags := Flags or SHGFI_SMALLICON;<br> SHGetFileInfo(PChar(Ext), 0, FileInfo, SizeOf(FileInfo), Flags);<br> Result := FileInfo.iIcon;<br>end;<br><br>