How to retrieve overlay icon associated with a file?

  • Thread starter Thread starter shadowscar
  • Start date Start date
S

shadowscar

Guest
I am in this strange situation where I need to check if an overlay icon is associated with a file. To do this I require either the whole icon with overlay icon masked to it or i need only the overlay icon associated with the icon.

I have tried using System.Drawing.Icon.ExtractAssociatedIcon(), but it returns only the file icon and not the overlay icon. Is there any way I could tweak this to get the ovelay masked with the icon?

Icon.ExtractAssociatedIcon(@"some file path");

I then tried to use Shell32.SHFILEINFO and the SHGetFileInfo() to return the system image list. I assumed that the System Image list would contain my overlay icon but to my surprise I could not find the overlay icon I was looking for. Following is the function used to achieve this

public static Icon GetFileIcon(string filepath, IconSize size, bool linkOverlay) { uint attributes = 0; attributes += Shell32.FILE_ATTRIBUTE_NORMAL; uint flags = Shell32.SHGFI_SYSICONINDEX | Shell32.SHGFI_SMALLICON | Shell32.SHGFI_ICON | Shell32.SHGFI_ADDOVERLAYS | Shell32.SHGFI_OVERLAYINDEX; Shell32.SHFILEINFO shfileinfo = new Shell32.SHFILEINFO(); IntPtr list = Shell32.SHGetFileInfo(filepath, attributes, ref shfileinfo, (uint)Marshal.SizeOf(shfileinfo), (uint)flags); int newflags = 0; newflags += Win32.ILD_TRANSPARENT; var a = (int)shfileinfo.iIcon >> 24; var listCount = Win32.ImageList_GetImageCount(list); Icon icon = (Icon)Icon.FromHandle(Win32.ImageList_GetIcon(list, a, newflags)).Clone(); return icon; }

This code works fine but it keeps returning the windows shortcut overlay icon when in fact I am looking for a custom overlay icon(which has been COM registered and I can see it visually)

Could someone please help me point out where I am going wrong?

Thanks!!

Continue reading...
 
Back
Top