tags:

views:

78

answers:

2

I am using the SHGetFileInfo api to get a handle to and display the icon associated with a particular file.

If the file has no icon associated with it Windows will return you the default one that it uses in explorer for unknown file types. In this case I don't want to display the icon.

How can I tell if the file has no associated icon and Windows is giving me back the default one?

On my system SHFILEINFO.iIcon is always equal to 3 in this case but i'm not sure how reliable that is and I expect there is a better way to check this.

Edit: I am targeting Windows XP and upwards

Thanks

+1  A: 

Which OS versions are you targeting? If you can assume Vista and later, there's an API SHGetStockIconInfo that you may find useful.

SHGetStockIconInfo(SIID_DOCNOASSOC, SHGSI_SYSICONINDEX, &sii)

will return the icon index you're looking for in sii.iSysImageIndex.

Mattias S
XP and Upwards. I'll update my post. Thanks for the info
Jamie
A: 

You could try passing a fictitious filename with an unknown extension to SHGetFileInfo(), keep track of which icon index it reports, and then compare that index to your real files.

Remy Lebeau - TeamB
You never know when the user will install some other application that registers that fictitious extension.
Franci Penov
You cold simply query the Registry for the registered file extensions beforehand, and then pick one that does not exist yet. Or dynamically generate a file extension randomly, check if it exists, and re-generate if needed (similar to how GetTempFileName() does when its uUnique parameter is set to 0).
Remy Lebeau - TeamB