C
chemstar
Unregistered / Unconfirmed
GUEST, unregistred user!
我根据一个字符串如‘aaa.doc’(这个文件并不实际存在),通过调用函数<br>来取得doc文件在系统内的图标索引,进而显示在一个listview内,用了如下的代码:<br><br> 请新建一个项目,在form上放一个button和一个listview,并设其viewstyle为vssmallicon<br>,然后用以下代码替掉原来的所有代码:<br> unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils,<br>Classes, Graphics, Controls,<br>Forms, Dialogs, ComCtrls,<br>StdCtrls, ShellAPI, ExtCtrls,<br>ImgList;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> ListView1: TListView;<br> procedure Button1Click(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> private<br><br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br>Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br>function GetFileIconIndex(FileName: string; Large: Boolean): Integer; { 获取图标的序号函数 }<br><br>var<br> Ext: string;<br> Flags: Integer;<br> FileInfo: TSHFILEINFO;<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>procedure TForm1.FormCreate(Sender: TObject);<br>var<br> shFileInfo: TSHFILEINFO;<br>begin<br> with ListView1 do { 分配系统资源给ListView1组件以显示图标 }<br>begin<br>SmallImages:=TImageList.CreateSize(32,32);<br>SmallImages.ShareImages:=True;<br>SmallImages.Handle:=ShGetFileInfo('*.*',0,<br>SHFileInfo, SizeOf(SHFileInfo),<br>SHGFI_LARGEICON or<br>SHGFI_ICON or SHGFI_SYSICONINDEX);<br><br>LargeImages:=TImageList.CreateSize(32,32);<br>LargeImages.ShareImages:=True;<br>LargeImages.Handle:=ShGetFileInfo('*.*',0,<br>SHFileInfo, SizeOf(SHFileInfo),<br>SHGFI_LARGEICON or<br>SHGFI_ICON or SHGFI_SYSICONINDEX);<br>end;<br><br><br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> listitem:tlistitem;<br>begin<br> ListItem:=ListView1.Items.Add;<br> ListItem.ImageIndex:=GetFileIconIndex('aaa.doc',false) ;<br>end;<br><br>end.<br>程序运行后单击会在listview内显示一个word的图标,但是我在win98下运行很正常,在win2000下却什么<br>也显示不出来!请高手看看是怎么回事!是不是98和2000的函数不一样?<br>