How to determine if there is an associated icon in a file

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

If the file does not have an associated icon, Windows will return you to the default, which it uses in File Explorer for unknown file types. In this case, I don't want to display the icon.

How can I tell if there is no associated file icon and Windows returns me the default?

On my system SHFILEINFO.iIcon

it is always 3 in this case, but I'm not sure how reliable it is and I expect there is a better way to test this.

Edit: I am targeting Windows XP and above

thank

+2


source to share


2 answers


What OS versions are you using for targeting? If you can assume Vista and later, there is an SHGetStockIconInfo API that you might find useful.

SHGetStockIconInfo(SIID_DOCNOASSOC, SHGSI_SYSICONINDEX, &sii) 

      



will return the index of the icons you are looking for in sii.iSysImageIndex.

+1


source


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



0


source







All Articles