TerpBRC
October 7th, 2002, 02:06 PM
I have been playing around with c-sharp and I have been trying to get my windows explorer-like program to retrieve the native icon for each file type from the system. That is, if I read a file of type ".txt", I want my program to know what system icon is that is associated with the extension/mime-type and display the corresponding icon in my listview.
Thanks in advance for all help!
V. Lorenzo
October 8th, 2002, 09:06 AM
Hi:
Some time ago I wrote a couple of papers with some tips about that, but in spanish and for Delphi. I'll try to resume that here (no sample code for the moment, sorry)
For obtaining the icon that represents a file type you have to dig a little bit into the windows registry. There you have to look for the executable associated with the file type, firstly, and, secondly, use an API function call to load the icon that the executable declares as it's program icon.
Let's do it using a sample file name, said Demo.txt. The file extension is .txt. Under the HKEY_CLASSES_ROOT look for the '.txt' entry, which is found as 'HKEY_CLASSES_ROOT\.txt'. There you will see a string value named 'Content Type' with the content value 'text/plain' and a default value of 'txtfile'.
Now you have to look (under the HKEY_CLASSES_ROOT key again) for the entry named 'txtfile', which is found as 'HKEY_CLASSES_ROOT\txtfile'. There you will see the key named 'HKEY_CLASSES_ROOT\txtfile\DefaultIcon', it's default value indicates the program file that contains the icon and the icon index inside the program as '%SystemRoot%\system32\shell32.dll,-152'.
I don't recall now the exact name for the api function that exstracts the icon (ExtractIcon, ExtractIconEx, or some like that) but you will surely find it in the IDE MSDN.
I hope this could be of some help.
VictorL