求助: 如何提取代表文件类型的图标?(100分)

  • 主题发起人 主题发起人 voolcano
  • 开始时间 开始时间
V

voolcano

Unregistered / Unconfirmed
GUEST, unregistred user!
根据系统资源,如何提取代表文件类型的图标。比方说扩展名为 .rar的文件是winrar压缩的文件,如何根据这个扩展名提取代表winrar压缩文件的图标?
 
通過註冊表的內容<br>首先;獲的HKEY_CLASSES_ROOT下面'.rar'的預設字段內容,這裡獲得的內容是WinRAR<br>然後;獲的HKEY_CLASSES_ROOT下面'WinRAR'-'DefaultIcon'的內容,該內容就是winrar压缩文件的图标對應的資訊。<br><br>最後通過程式獲的該DLL或EXE對音的圖標<br>
 
[:)]<br>提取.exe or .dll文件中的图标要用到函数ExtractIconEx<br><br>HICON ExtractIconEx(<br>&nbsp; &nbsp; LPCSTR lpszFile, <br>&nbsp; &nbsp; int nIconIndex, <br>&nbsp; &nbsp; HICON FAR * phiconLarge, <br>&nbsp; &nbsp; HICON FAR * phiconSmall, <br>&nbsp; &nbsp; UINT nIcons <br>&nbsp; &nbsp;);
 
1. SHGetFileInfo 可以得到系统文件ImageList的巨冰和索引 (参考TSHellListView)<br>2. 通过读注册表取得具体位置 然后 API取得图标(同holyknight)<br>3. 在Shell Function里边也有通过文件类型直接取得图标物理位置的方法,手头没有MSDN/的SDK,你自己参考查找下
 
已经解决,谢谢大家!这是我写的函数。也贡献给遇到相同问题的人。<br><br>//----------------------------------------------------------------------------//<br>//功能 :获取关联文件类型的图标。 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //<br>//参数 :ext : 文件扩展名。 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //<br>//返回值 : 提取的图标句柄。 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//<br>//----------------------------------------------------------------------------//<br>function GetAssociatedFileIcon(ext : String) : THandle;<br>var<br>&nbsp;tmpReg : TRegistry;<br>&nbsp;tmpItem, PathName : string;<br>&nbsp;ipos : integer;<br>&nbsp;Index : word;<br>begin<br>&nbsp; result := 0;<br>&nbsp; tmpReg := TRegistry.Create;<br>&nbsp; with TmpReg do<br>&nbsp; begin<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; RootKey := HKEY_CLASSES_ROOT;<br>&nbsp; &nbsp; &nbsp; if OpenKey(ext, false) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; tmpItem := ReadString(''); &nbsp; //读某项的缺省值好像这样才能读出来,奇怪。<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseKey;<br>&nbsp; &nbsp; &nbsp; &nbsp; TmpItem := TmpItem + '/DefaultIcon';<br>&nbsp; &nbsp; &nbsp; &nbsp; if OpenKey(tmpItem, False) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tmpItem := ReadString('');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CloseKey;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iPos := pos(',', TmpItem);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if iPos &gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PathName := Copy(TmpItem,1, iPos - 1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Index := StrToInt(Copy(TmpItem,iPos + 1, Length(TmpItem) - iPos));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := ExtractAssociatedIcon(Hinstance, Pchar(PathName), Index);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; Free;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br>
 
谢谢大家。
 

Similar threads

回复
0
查看
1K
不得闲
S
回复
0
查看
916
SUNSTONE的Delphi笔记
S
S
回复
0
查看
894
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部