Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Edit: <a href="https://stackoverflow.com/questions/462270/get-file-icon-used-by-shell">Here</a> is a version without PInvoke.</p> <pre><code>[StructLayout(LayoutKind.Sequential)] public struct SHFILEINFO { public IntPtr hIcon; public IntPtr iIcon; public uint dwAttributes; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string szDisplayName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] public string szTypeName; }; public const uint SHGFI_ICON = 0x100; public const uint SHGFI_LARGEICON = 0x0; // 'Large icon public const uint SHGFI_SMALLICON = 0x1; // 'Small icon [DllImport("shell32.dll")] public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags); [DllImport("User32.dll")] public static extern int DestroyIcon(IntPtr hIcon); public static System.Drawing.Icon GetSystemIcon(string sFilename) { //Use this to get the small Icon IntPtr hImgSmall; //the handle to the system image list //IntPtr hImgLarge; //the handle to the system image list APIFuncs.SHFILEINFO shinfo = new APIFuncs.SHFILEINFO(); hImgSmall = APIFuncs.SHGetFileInfo(sFilename, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), APIFuncs.SHGFI_ICON | APIFuncs.SHGFI_SMALLICON); //Use this to get the large Icon //hImgLarge = SHGetFileInfo(fName, 0, // ref shinfo, (uint)Marshal.SizeOf(shinfo), // Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON); //The icon is returned in the hIcon member of the shinfo struct System.Drawing.Icon myIcon = (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shinfo.hIcon).Clone(); DestroyIcon(shinfo.hIcon); // Cleanup return myIcon; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload