Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to get the handle to the icon of a registered extension Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
29-Aug-02
Category
Win API
Language
Delphi 2.x
Views
122
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas 

How can I get the icon of a registered extension (in the windows registry)?

Answer:

Solve 1:

First get the pointer to the operating systems image list and assign it to your own.

{Image List From System}
ImageListHandle := SHGetFileInfo('C:\', 0, FileInfo, SizeOf(FileInfo), 
SHGFI_SYSICONINDEX  or SHGFI_SMALLICON);
SendMessage(ListView1.Handle, LVM_SETIMAGELIST, LVSIL_SMALL, 
LParam(ImageListHandle));

Then in your listview you can extract out the icon by doing this:
1   
2   function GetShellIcon(FileName: string; Folder: Boolean): Integer;
3   var
4     FileInfo: TSHFileInfo;
5     ImageHandle: THandle;
6     Flag: Integer;
7   begin
8     if Folder then
9       Flag := FILE_ATTRIBUTE_DIRECTORY
10    else
11      Flag := FILE_ATTRIBUTE_NORMAL;
12    SHGetFileInfo(PChar(FileName), Flag, FileInfo, SizeOf(FileInfo), 
13  SHGFI_SYSICONINDEX or SHGFI_SMALLICON or SHGFI_UseFileAttributes);
14    Result := FileInfo.IIcon;
15  end;


Notice: At the bottom I assign the icon index from the IICON field of the data 
returned by SHGetFileInfo. So my function gets passed a filename and returns an 
image index. You could change the IICON field to the HICON field and then I believe 
you would be getting the handle to an icon.


Solve 2:

The SHGFI_SYSICONINDEX in the above code snippet is going to place the index of the 
icon in the system image list (a handle to which is being returned as the result of 
the SHGetFileInfo function call) in the FileInfo.iIcon member. Use the SHGFI_ICON 
flag instead to get an icon handle in HIcon.
16  
17  function GetShellIcon(FileName: string; Folder: Boolean): Integer;
18  var
19    FileInfo: TSHFileInfo;
20    ImageHandle: THandle;
21    Flag: Integer;
22    IconHandle: THandle;
23  begin
24    if Folder then
25      Flag := FILE_ATTRIBUTE_DIRECTORY
26    else
27      Flag := FILE_ATTRIBUTE_NORMAL;
28    SHGetFileInfo(PChar(FileName), Flag, FileInfo, SizeOf(FileInfo),
29      SHGFI_ICON or SHGFI_SMALLICON or SHGFI_UseFileAttributes);
30    Result := FileInfo.IIcon;
31    IconHandle := FileInfo.HIcon;
32  end;



Solve 3:

One method of getting the associated icon with a particular file is to first 
populate an imagelist with registered system icons (this example is for small 
icons, you could do the same for large). In this example, iIndex will be the 
ImageList item for the particular file.

33  var
34    dwSmallIcon: DWord;
35    pFileInfo: TshFileInfo;
36    iIndex: Integer;
37  begin
38    dwSmallIcon := SHGetFileInfo('', 0, FileInfo, SizeOf(TshFileInfo), (SHGFI_ICON or
39      SHGFI_SMALLICON or SHGFI_SYSICONINDEX));
40    ImageList1.Handle := dwSmallIcon; {imagelist}
41    ImageList1.ShareImages := True;
42    FillChar(pFileInfo, SizeOf(TshFileInfo), 0);
43    shGetFileInfo(pName, 0, pFileInfo, SizeOf(TshFileInfo), SHGFI_SYSICONINDEX or
44      SHGFI_SMALLICON or SHGFI_OPENICON);
45    iIndex := pFileInfo.iIcon;
46  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC