public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, out SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
/// <summary> /// Gets folder icon /// </summary> /// <param name="size"></param> /// <param name="folderType"></param> /// <returns></returns> public static Icon GetFolderIconI(IconSize size, FolderType folderType) { // Need to Add size check, although errors generated at present! uint flags = SHGFI_ICON | SHGFI_USEFILEATTRIBUTES; if (FolderType.Open == folderType) { flags += SHGFI_OPENICON; } if (IconSize.Small == size) { flags += SHGFI_SMALLICON; } else { flags += SHGFI_LARGEICON; } // Get the folder icon SHFILEINFO shfi = new SHFILEINFO(); IntPtr res = SHGetFileInfo(@"C:\Windows", FILE_ATTRIBUTE_DIRECTORY, out shfi, (uint)Marshal.SizeOf(shfi), flags); if (res == IntPtr.Zero) throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); // Load the icon from an HICON handle Icon.FromHandle(shfi.hIcon); // Now clone the icon, so that it can be successfully stored in an ImageList Icon icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone(); DestroyIcon(shfi.hIcon); // Cleanup return icon; }