diff --git a/Windows.Shell/ShellImageList.cs b/Windows.Shell/ShellImageList.cs index 7d7f613c..c9045de3 100644 --- a/Windows.Shell/ShellImageList.cs +++ b/Windows.Shell/ShellImageList.cs @@ -7,18 +7,23 @@ using static Vanara.PInvoke.User32; namespace Vanara.Windows.Shell { - /// Used to determine the size of the icon returned by . + /// Used to determine the size of the icon returned by ShellImageList.GetSystemIcon. public enum ShellImageSize { /// - /// The image size is normally 32x32 pixels. However, if the Use large icons option is selected from the Effects section of the Appearance tab in - /// Display Properties, the image is 48x48 pixels. + /// The image size is normally 32x32 pixels. However, if the Use large icons option is selected from the Effects section of the + /// Appearance tab in Display Properties, the image is 48x48 pixels. /// Large = SHIL.SHIL_LARGE, + /// The image is the Shell standard small icon size of 16x16, but the size can be customized by the user. Small = SHIL.SHIL_SMALL, - /// The image is the Shell standard extra-large icon size. This is typically 48x48, but the size can be customized by the user. + + /// + /// The image is the Shell standard extra-large icon size. This is typically 48x48, but the size can be customized by the user. + /// ExtraLarge = SHIL.SHIL_EXTRALARGE, + /// Windows Vista and later. The image is normally 256x256 pixels. Jumbo = SHIL.SHIL_JUMBO } @@ -31,6 +36,22 @@ namespace Vanara.Windows.Shell { private static HIMAGELIST hSystemImageList; + /// Gets the Shell icon for the given file name or extension. + /// The file name or extension . + /// + /// Flags to specify the type of the icon to retrieve. This uses the method and can only retrieve small or large icons. + /// + /// An instance if found; otherwise . + public static Icon GetFileIcon(string fileNameOrExtension, ShellIconType iconType = ShellIconType.Large) + { + var shfi = new SHFILEINFO(); + var ret = SHGetFileInfo(fileNameOrExtension, 0, ref shfi, SHFILEINFO.Size, SHGFI.SHGFI_USEFILEATTRIBUTES | SHGFI.SHGFI_ICON | (SHGFI)iconType); + if (ret == IntPtr.Zero) + ret = SHGetFileInfo(fileNameOrExtension, 0, ref shfi, SHFILEINFO.Size, SHGFI.SHGFI_ICON | (SHGFI)iconType); + return ret == IntPtr.Zero ? null : shfi.hIcon.ToIcon(); + } + /// Gets the system icon for the given file name or extension. /// The file name or extension. /// Size of the icon. @@ -55,18 +76,5 @@ namespace Vanara.Windows.Shell SHGetImageList((SHIL)iconSize, typeof(IImageList).GUID, out var il).ThrowIfFailed(); return il.GetIcon(index, IMAGELISTDRAWFLAGS.ILD_TRANSPARENT)?.ToIcon(); } - - /// Gets the Shell icon for the given file name or extension. - /// The file name or extension . - /// Flags to specify the type of the icon to retrieve. This uses the method and can only retrieve small or large icons. - /// An instance if found; otherwise . - public static Icon GetFileIcon(string fileNameOrExtension, ShellIconType iconType = ShellIconType.Large) - { - var shfi = new SHFILEINFO(); - var ret = SHGetFileInfo(fileNameOrExtension, 0, ref shfi, SHFILEINFO.Size, SHGFI.SHGFI_USEFILEATTRIBUTES | SHGFI.SHGFI_ICON | (SHGFI)iconType); - if (ret == IntPtr.Zero) - ret = SHGetFileInfo(fileNameOrExtension, 0, ref shfi, SHFILEINFO.Size, SHGFI.SHGFI_ICON | (SHGFI)iconType); - return ret == IntPtr.Zero ? null : shfi.hIcon.ToIcon(); - } } -} +} \ No newline at end of file