public static Icon GetFileIcon(string cFile) { // return Icon.ExtractAssociatedIcon(cFile).; SHFILEINFO shi = new SHFILEINFO(); IntPtr hIcon = SHGetFileInfo(cFile, 0, ref shi, (uint)(Marshal.SizeOf(shi)), SHGFI_SMALLICON | SHGFI_ICON ); if (shi.hIcon != IntPtr.Zero) { Icon ret = (Icon) Icon.FromHandle(shi.hIcon).Clone(); DestroyIcon(shi.hIcon); return ret; } else return null; }
public static Icon GetFolderIcon(string cFolder, bool Open=false) { SHFILEINFO shi = new SHFILEINFO(); uint uFlags = SHGFI_SMALLICON | SHGFI_ICON; if (Open) uFlags |= SHGFI_OPENICON; IntPtr hIcon = SHGetFileInfo(cFolder, 0, ref shi, (uint)Marshal.SizeOf(shi), uFlags); if (shi.hIcon != IntPtr.Zero) { Icon ret = (Icon) Icon.FromHandle(shi.hIcon).Clone(); bool l = DestroyIcon(shi.hIcon); return ret; } else return null; }
public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);