I think I understand what you're asking: how do I know what icon is
associated with a file of a given type by Explorer so that I can display the
same icon as Explorer would? Is that what you're saying?
If so, the association of a file type (extension), with an icon is done
through the registry. For example, here's a sample that associates TXT
files with my application, cepad, and assigns an icon from that to them:
[HKEY_CLASSES_ROOT\.txt]
@="txtfile"
[HKEY_CLASSES_ROOT\txtfile]
@="Text File"
[HKEY_CLASSES_ROOT\txtfile\DefaultIcon]
@="\\Flash\\CEPad.exe,-101"
[HKEY_CLASSES_ROOT\txtfile\Shell\Open\Command]
@="\"\\Flash\\CEPad.exe\" %1"
The DefaultIcon item is the one that you'll need to parse. It gives the
location of a file, optionally followed by a comma and the resource ID
within the indicated file. In this case, the icon resource in cepad.exe
with ID = 101 (the minus sign is a bit of a mystery), is the one used by
Explorer to display the file.
You *may* be able to use SHGetFileInfo(..., SHGFI_ICON) to hide your access
to the registry items, also. You'd have to try that, to be sure.
Paul T.
new.microsoft.com said:
How do I get the icon associated with a file??? I am trying to build a
file-explorer application and want to display the icon of each file.
Thanks.