public Icon LoadIcon(string filename, LoadIconFlags flags) { if (!System.IO.Directory.Exists(filename) && !System.IO.File.Exists(filename)) { return(null); } SHFILEINFO fileinfo = new SHFILEINFO(); SHGFIFLAGS gfiflags = SHGFIFLAGS.SHGFI_ICON;// | SHGFIFLAGS.SHGFI_ADDOVERLAYS; if ((flags & LoadIconFlags.LargeIcon) != 0) { gfiflags |= SHGFIFLAGS.SHGFI_LARGEICON; } else if ((flags & LoadIconFlags.SmallIcon) != 0) { gfiflags |= SHGFIFLAGS.SHGFI_SMALLICON; } if ((flags & LoadIconFlags.OpenIcon) != 0) { gfiflags |= SHGFIFLAGS.SHGFI_OPENICON; } int hres = Shell32.SHGetFileInfo(filename, 0, ref fileinfo, Marshal.SizeOf(fileinfo), gfiflags); Icon ico = Icon.FromHandle(fileinfo.hIcon); Bitmap bm1 = ico.ToBitmap(); //Debug.Write("Icon " + bm1.Size.ToString() + " : " + bm1.PixelFormat.ToString() + "\r\n"); return(ico); }
private static extern int SHGetFileInfo( string pszPath, int dwFileAttributes, ref SHFILEINFO psfi, int cbFileInfo, SHGFIFLAGS uFlags );