retreiving icon associated with a file type without using SHGetFileInfo?
I only know how to do it useing the SHGetFileInfo() API. But that function needs an actual file to exist. I'm wondering if there is a way to get the icon associated with a file without using SHGetFileInfo()???
I know I could create a dummy file and then use it to call SHGetFileInfo() but I rather not do that if there's another way :)
Re: retreiving icon associated with a file type without using SHGetFileInfo?
Have a look at HKEY_CLASSES_ROOT hive, and notice that each extension is listed there. If you open up a key, look at the (default) value for it.
I'm looking at ".bmp" and the default value for it is "Paint.Picture"
Now in the same hive (HKEY_CLASSES_ROOT) look up "Paint.Picture"
There is a subfolder called "DefaultIcon." The (default) value of this folder will tell you the module name, and icon index, separated by a comma. From here, just call ExtractIcon() on that module, specifying that specfic index.
Re: retreiving icon associated with a file type without using SHGetFileInfo?
aaaaaaah many thanks:D:D:D sounds cool. Umm would you recommend this method though? just curious:)
Re: retreiving icon associated with a file type without using SHGetFileInfo?
You're welcome
And, I see no harm in using it. Beats creating a temp file, anyway.
Re: retreiving icon associated with a file type without using SHGetFileInfo?
If you use SHGetFileInfo you can use the SHGFI_USEFILEATTRIBUTES attribute if the file doesn't exist.
This way you can extract an icon just be using "*.jpg" as filename.
Re: retreiving icon associated with a file type without using SHGetFileInfo?
aah even more interesting:D I'll take a look at that....
I'm guessnig that's a constant I need to pass as the dwFileAttribute parameter?:D
Re: retreiving icon associated with a file type without using SHGetFileInfo?
True.
VB Code:
Private Const SHGFI_USEFILEATTRIBUTES As Integer = &H10
Re: retreiving icon associated with a file type without using SHGetFileInfo?
There is a complete class for this in the codebank. Pretty cool.
http://vbforums.com/showthread.php?t=330983
1 Attachment(s)
Re: retreiving icon associated with a file type without using SHGetFileInfo?
Quote:
Originally Posted by MrPolite
aah even more interesting:D I'll take a look at that....
I'm guessnig that's a constant I need to pass as the dwFileAttribute parameter?:D
Since I'm feeling generous today, I'll give you the source code for an ActiveX dll I'm using in a program to populate a image list control with file extension icons. It's made in VB6.
Re: retreiving icon associated with a file type without using SHGetFileInfo?
Quote:
Originally Posted by kaffenils
It's made in VB6.
This is the VB.Net forum though. Thanks all the same I'm sure its lovely.
Re: retreiving icon associated with a file type without using SHGetFileInfo?
Quote:
Originally Posted by wossname
This is the VB.Net forum though. Thanks all the same I'm sure its lovely.
Yes I know it's vb.net, but it should be easy to convert from vb6 to .net
Re: retreiving icon associated with a file type without using SHGetFileInfo?
naah I dont want vb6 stuff:D not even vb.net.... I'm writing in C#. I just ask here cuz I get more responses:D:D:D:D
I still havent started workign on this part of my app, but will do soon. I like what pax said, and if that didnt work then I'll look at megatran's, and then maybe wossname's:D:D
Kaffenils thanks for the reply though, I'll give you a positive feedback as soon as VBF lets me rate people again :D