private static IntPtr GetIconHandleFromFilePath(string filepath, IconSizeEnum iconsize) { var shinfo = new Shell.SHFILEINFO(); const uint SHGFI_SYSICONINDEX = 0x4000; const int FILE_ATTRIBUTE_NORMAL = 0x80; uint flags = SHGFI_SYSICONINDEX; return(getIconHandleFromFilePathWithFlags(filepath, iconsize, ref shinfo, FILE_ATTRIBUTE_NORMAL, flags)); }
private static IntPtr GetIconHandleFromFolderPath(string folderpath, IconSizeEnum iconsize) { var shinfo = new Shell.SHFILEINFO(); const uint SHGFI_ICON = 0x000000100; const uint SHGFI_USEFILEATTRIBUTES = 0x000000010; const int FILE_ATTRIBUTE_DIRECTORY = 0x00000010; uint flags = SHGFI_ICON | SHGFI_USEFILEATTRIBUTES; return(getIconHandleFromFilePathWithFlags(folderpath, iconsize, ref shinfo, FILE_ATTRIBUTE_DIRECTORY, flags)); }
private static IntPtr getIconHandleFromFilePathWithFlags( string filepath, IconSizeEnum iconsize, ref Shell.SHFILEINFO shinfo, int fileAttributeFlag, uint flags) { const int ILD_TRANSPARENT = 1; var retval = SHGetFileInfo(filepath, fileAttributeFlag, ref shinfo, Marshal.SizeOf(shinfo), flags); if (retval == 0) { throw (new System.IO.FileNotFoundException()); } var iconIndex = shinfo.iIcon; var iImageListGuid = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950"); Shell.IImageList iml; var hres = SHGetImageList((int)iconsize, ref iImageListGuid, out iml); var hIcon = IntPtr.Zero; hres = iml.GetIcon(iconIndex, ILD_TRANSPARENT, ref hIcon); return(hIcon); }
public static extern int SHGetFileInfo( string pszPath, int dwFileAttributes, ref Shell.SHFILEINFO psfi, int cbFileInfo, uint uFlags);