Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows file association?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hi everybody !
How I can get an icon that windows associates with certain file extention?
For example: for *.mp3 files.
If somebody knows please, at least, give direction where to look for that staff.
Thanks in advance!
 
What i meant was how at run time I can find out icons for file extentions like they shown in Windows Explorer, so I could use them in ListView control.
Thanks for responce.
plse.
 
Hmm. This is interesting, because most of the time, icons are stored as resources rather than straight .ico files.

I can't answer this, but hopefully I can point you in the right direction.

First of all, you will need to poke around in the registry. Say for example you want to find the icon associated with a .txt file...

In the registry, there will be a key under HKEY_CLASSES_ROOT called ".txt". This will have a default value associated with it - this is "txtfile". Now this is actually the name of another registry key, so go to HKEY_CLASSES_ROOT\txtfile.
This will have a subkey called DefaultIcon, and this will give you the icon you're looking for.

Now the above should work for any registered file type. (eg. .vbp files have a ".vbp" key, which points you to another key called VisualBasic.Project, which has a subkey called DefaultIcon, etc. etc.

Now this is where my experience ends. I can tell you that the entry in this DefaultIcon is giving you resource information. For example, the VisualBasic.DefaultIcon key says something like "somedrive/somepath/vb6.exe,16". This tells you that the icon is the 16th icon in this exe.

You can actually view these icons if you want. Right-click a shortcut, click Change Icon, then Browse and select the vb6.exe (or what ever .exe or .dll or whatever you want) and it will display all the icons stored in that file.

To extract the icon itself you will need to load the library and pull the resource and for this you will need a few API calls. Like I say, I have not gone this far before, so I will leave that bit up to you!

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top