private static Icon GetIcon(string fileName, uint flags) { SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hImgSmall = SHGetFileInfo(fileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | flags); Icon icon = (Icon)System.Drawing.Icon.FromHandle(shinfo.hIcon).Clone(); DestroyIcon(shinfo.hIcon); return icon; }
public static Bitmap GetBitmap(string fileName) { SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hImgSmall = SHGetFileInfo(fileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_SMALLICON); Bitmap icon = (Bitmap)System.Drawing.Bitmap.FromHicon(shinfo.hIcon).Clone(); DestroyIcon(shinfo.hIcon); return icon; }
public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);