有关获取文件图标和名称等信息的API函数的讨论(50分)

  • 主题发起人 主题发起人 miqi2000
  • 开始时间 开始时间
M

miqi2000

Unregistered / Unconfirmed
GUEST, unregistred user!
哪些API函数可以获得文件图标和名称等信息,最好有详细的代码说明。<br> 如: ExtractIcon可以获得EXE文件的图标,要获得Word,dbf等文件的图标该用什么函数?
 
给个邮箱发给你
 
yyhwjy@163.net,谢谢
 
怎么没人感兴趣吗?<br>自己顶下。
 
已经发到你邮箱。
 
怎么没有收到呢?<br>能再发一次吗?<br>yyhwjy@tom.com<br>谢谢!
 
This message is generated by COREMAIL email system.<br>I'm sorry to have to inform you that the message returned<br><br><br>你发送到yyhwjy@163.net的邮件由于以下原因被退回 : yyhwjy@163.net SMTP error, RCPT TO: 501 #5.1.1 bad address yyhwjy@163.net
 
yyhwjy@tom.com 或 <br>nx_yc_yyhao@sohu.com<br>谢谢!
 
procedure GetExeIcon(FileName:string);<br>var<br> &nbsp;icon:Ticon;<br>begin<br> &nbsp;icon := TIcon.create;<br> &nbsp;try<br> &nbsp; &nbsp;icon.handle := extractIcon(hInstance,pchar(FileName),0);<br> &nbsp;finally<br> &nbsp; &nbsp;icon.free;<br> &nbsp;end;<br>end;<br><br>附 &nbsp;ExtarctIcon 的联机帮助<br><br>the ExtractIcon function retrieves the handle of an icon from the specified executable file, dynamic-link library (DLL), or icon file. <br><br>这个函数可以从可执行文件,动态连接库,或 icon 文件中取得 icon 的 handle<br><br>HICON ExtractIcon(<br><br> &nbsp; &nbsp;HINSTANCE hInst, // instance handle &nbsp;实例句柄,传 hinstance就行<br> &nbsp; &nbsp;LPCTSTR lpszExeFileName, // filename of file with icon &nbsp; 文件的路径<br> &nbsp; &nbsp;UINT nIconIndex // index of icon to extract &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 图标索引<br> &nbsp; ); <br> <br><br>Parameters<br><br>hInst<br><br>Identifies the instance of the application calling the function. <br><br>lpszExeFileName<br><br>Points to a null-terminated string specifying the name of an executable file, DLL, or icon file. <br><br>nIconIndex<br><br>Specifies the index of the icon to retrieve. If this value is 0, the function returns the handle of the first icon in the specified file. If this value is -1, the function returns the total number of icons in the specified file. <br><br>值为 0 ,则返回第一个 icon的 handle ,为 -1 &nbsp;则返回 icon 的总数<br><br> <br><br>Return Values<br><br>If the function succeeds, the return value is the handle to an icon. If the file specified was not an executable file, DLL, or icon file, the return is 1. If no icons were found in the file, the return value is NULL.<br><br><br>注意:要用 -1 来返回 icon 的个数时,由于 uInt 是无符号类型,所以提示为<br><br>Constant expression violates subrange bounds <br><br>解决办法为用 $FFFFFFFF 来代替 -1<br><br>这可得到的是 32 * 32 大小的图标<br><br>-------------------------------------------<br>这就是HubDog的《Delphi之未经证实的葵花宝典version 1.8》 中的有关提取图标的内容,<br>请自己试一试吧<br><br><br> &nbsp; WINSHELLAPI DWORD WINAPI SHGetFileInfo(<br> &nbsp; &nbsp;LPCSTR &nbsp;pszPath,<br> &nbsp; &nbsp;DWORD &nbsp;dwFileAttributes,<br> &nbsp; &nbsp;SHFILEINFO FAR &nbsp;*psfi,<br> &nbsp; &nbsp;UINT &nbsp;cbFileInfo,<br> &nbsp; &nbsp;UINT &nbsp;uFlags<br> &nbsp; );<br>它的作用是:取回文件系统中的一个对象的信息,对象可以是文件、文件夹、<br>目录或驱动器的根目录。经过三个多小时的调试,我终于完全弄明白怎样取<br>得并显示一个文件的图标了:包括大图标、小图标,象资源管理器上的那样。<br>操作过程大体如下:<br>var ShFileInfo: TSHFILEINFO;<br> &nbsp; &nbsp;FileList:TListView;<br>begin<br> &nbsp;...<br> &nbsp;Result := FileList.Items.Add;<br> &nbsp;with Result do<br> &nbsp;begin<br> &nbsp; &nbsp;Caption:=filename;<br> &nbsp; &nbsp;ShGetFileInfo(pchar(vartostr(filename)), 0, SHFileInfo, SizeOf(SHFileInfo),<br> &nbsp; &nbsp; &nbsp; &nbsp;SHGFI_SMALLICON or SHGFI_SYSICONINDEX or SHGFI_TYPENAME)=0 then<br> &nbsp; &nbsp; &nbsp; &nbsp;showmessage('error in shgetfileinfo');<br> &nbsp; &nbsp;ImageIndex := SHFileInfo.iIcon;<br> &nbsp;end;<br> &nbsp;...<br>end;<br>这是最关键的几个地方,中间省略了许多细节。<br>另:我在6月17日的笔记里提到ExtractAssociatedIcon()和ExtractIcon()函数,<br>也可以提取文件的图标,但是速度比这个方法要慢上许多,而且我不会用它们提<br>取小图标。<br>//////////////////////////////////////////////////////////////<br>uses ShellApi;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;Icon : hIcon;<br> &nbsp;IconIndex : word;<br><br>begin<br> Icon := ExtractAssociatedIcon(HInstance,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'C:/SomePath/SomeFile.ext',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IconIndex);<br> DrawIcon(Form1.Canvas.Handle, 10, 10, Icon);<br>end;
 
下次有空我给你发,多的是,这个还要这么麻烦
 
后退
顶部