public static Icon GetIcon(string path, bool selected) { ShellFileInformationStructure info = new ShellFileInformationStructure(true); int cbFileInfo = Marshal.SizeOf(info); SHGFI flags; if (!selected) flags = SHGFI.SHGFI_ICON | SHGFI.SHGFI_SMALLICON; else flags = SHGFI.SHGFI_ICON | SHGFI.SHGFI_SMALLICON | SHGFI.SHGFI_OPENICON; ShellApiNativeMethods.SHGetFileInfo (path, 256, out info,(uint)cbFileInfo, flags); return Icon.FromHandle(info.IconHandle); }
internal static extern Int32 SHGetFileInfo (string pszPath, uint dwFileAttributes, out ShellFileInformationStructure psfi, uint cbfileInfo, SHGFI uFlags);