如何用ShGetFileInfo函数获取图标?(50分)

  • 主题发起人 主题发起人 redboy
  • 开始时间 开始时间
R

redboy

Unregistered / Unconfirmed
GUEST, unregistred user!
我用以下函数获取文件和文件夹的图标,不知如何获取系统图标,如‘我的电脑’‘ 网络邻居’等 ?<br>function GetFileIconIndex<br>(FileName:string):integer;<br>&nbsp; { 获取图标的序号函数 }<br>var<br>&nbsp; Ext:String;<br>begin<br>&nbsp; Ext:=FileName;<br>&nbsp; ShGetFileInfo(Pchar(Ext), 0, SHFileInfo,SizeOf(SHFileInfo), SHGFI_LARGEICON or<br>&nbsp; &nbsp; SHGFI_SYSICONINDEX or SHGFI_TYPENAME);<br>&nbsp; Result:=SHFileInfo.iIcon; <br>&nbsp; { 返回获取的图标序号 }<br>end;
 
可以先用SHGetSpecialFolderLocation获得一个LPITEMIDLIST类型的指针,再根据这个指针用ShGetFileInfo就可以得到“我的电脑”“网上邻居”之类的图标了。<br>
 
to csowl: &nbsp;能不能整具体点 ! &nbsp; 最好来段源码!!!!! &nbsp; 谢谢你的参与!!!<br>
 
&nbsp; &nbsp;虽然用以上方法获得全部图标时,包含‘我的电脑’和‘ 网络邻居’图标。<br>&nbsp; &nbsp; 但要具体地获得某个图标,不能用以上方法,<br>因为‘我的电脑’和‘ 网络邻居’不能用“路径”表示。<br><br>其实这两种图标,用户是可以修改的。要想获得系统默认的图标,用以下方法:<br>在 Form 上放一 TImage,两个按钮。不要忘了连接按钮的点击事件。<br>在 win 98 下成功获得!!!!<br><br>procedure TForm1.Button8Click(Sender: TObject);<br>begin &nbsp; //获得“我的电脑”图标<br>&nbsp; image1.Picture.Icon.Handle:=<br>&nbsp; ExtractIcon (Handle,'c:/windows/explorer.exe',0);<br>end;<br><br>procedure TForm1.Button9Click(Sender: TObject);<br>begin &nbsp; //获得“网上邻居”图标<br>&nbsp; image1.Picture.Icon.Handle:=<br>&nbsp; ExtractIcon (Handle,'c:/windows/system/shell32.dll',18);<br>end;<br>
 
同意jsxjd。<br><br>to redboy:<br>如果要用SHGetFileInfo的话,试一试:<br>SHGetSpecialFolderLocation(NULL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CSIDL_DESKTOP,//桌面<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;pIdList);<br>SHFILEINFO FileInfo;<br>SHGetFileInfo(pIdList,// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LPCTSTR pszPath,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,// &nbsp; &nbsp;DWORD dwFileAttributes,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;FileInfo,// &nbsp; SHFILEINFO* psfi,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sizeof(FileInfo),// &nbsp; &nbsp; &nbsp;UINT cbFileInfo,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SHGFI_PIDL|SHGFI_SYSICONINDEX// &nbsp; &nbsp;UINT uFlags<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>可以从SHFILEINFO类型的FileInfo中得到图标在系统Imagelist中的序号。
 
因为在程序中其它图标用SHGetFileInfo取得,所以:<br><br>to jsxjd: 你的方法可行,但我不需要 :-) 。<br><br>to csowl: 你的方法我需要,但我不知如何用,试过多次 :-( 。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 最好更具体一些......
 
后退
顶部