mirror of https://github.com/dahall/Vanara.git
Changed icon retrieval methods to use ShellImageList.
parent
ca7ca983ca
commit
d9337cb5d2
|
@ -3,7 +3,6 @@ using System.Drawing;
|
|||
using System.IO;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using static Vanara.PInvoke.ComCtl32;
|
||||
using static Vanara.PInvoke.Kernel32;
|
||||
using static Vanara.PInvoke.Macros;
|
||||
using static Vanara.PInvoke.Shell32;
|
||||
|
@ -148,17 +147,7 @@ namespace Vanara.Windows.Shell
|
|||
|
||||
/// <summary>Gets the icon for this shell item from the system.</summary>
|
||||
/// <value>The system icon on success; <c>null</c> on failure.</value>
|
||||
public Icon SystemIcon
|
||||
{
|
||||
get
|
||||
{
|
||||
var shfi = new SHFILEINFO();
|
||||
var hImageList = SHGetFileInfo(FullPath, 0, ref shfi, SHFILEINFO.Size, SHGFI.SHGFI_SYSICONINDEX);
|
||||
if (hImageList == IntPtr.Zero) return null;
|
||||
var hIcon = ImageList_GetIcon(hImageList, shfi.iIcon, IMAGELISTDRAWFLAGS.ILD_NORMAL);
|
||||
return IconLocation.GetClonedIcon(hIcon);
|
||||
}
|
||||
}
|
||||
public Icon SystemIcon => ShellImageList.GetSystemIcon(FullPath);
|
||||
|
||||
/// <summary>Gets the type name for the file.</summary>
|
||||
public string TypeName { get; private set; }
|
||||
|
@ -169,15 +158,7 @@ namespace Vanara.Windows.Shell
|
|||
/// <summary>Gets the icon defined by the set of flags provided.</summary>
|
||||
/// <param name="iconType">Flags to specify type of the icon.</param>
|
||||
/// <returns><see cref="Icon"/> if successful; <c>null</c> otherwise.</returns>
|
||||
public Icon GetIcon(ShellIconType iconType = ShellIconType.Large)
|
||||
{
|
||||
const SHGFI baseFlags = SHGFI.SHGFI_USEFILEATTRIBUTES | SHGFI.SHGFI_ICON;
|
||||
var shfi = new SHFILEINFO();
|
||||
var ret = SHGetFileInfo(FullPath, 0, ref shfi, SHFILEINFO.Size, baseFlags | (SHGFI)iconType);
|
||||
if (ret == IntPtr.Zero)
|
||||
ret = SHGetFileInfo(FullPath, 0, ref shfi, SHFILEINFO.Size, SHGFI.SHGFI_ICON | (SHGFI)iconType);
|
||||
return ret == IntPtr.Zero ? null : IconLocation.GetClonedIcon(shfi.hIcon);
|
||||
}
|
||||
public Icon GetIcon(ShellIconType iconType = ShellIconType.Large) => ShellImageList.GetFileIcon(FullPath, iconType);
|
||||
|
||||
/// <summary>Returns a <see cref="System.String"/> that represents this instance.</summary>
|
||||
/// <returns>A <see cref="System.String"/> that represents this instance.</returns>
|
||||
|
|
Loading…
Reference in New Issue