Esempio n. 1
0
        /// <summary>Gets the system icon for the given file name or extension.</summary>
        /// <param name="fileNameOrExtension">The file name or extension.</param>
        /// <param name="iconSize">Size of the icon.</param>
        /// <returns>An <see cref="Icon"/> instance if found; otherwise <see langword="null"/>.</returns>
        public static Icon GetSystemIcon(string fileNameOrExtension, ShellImageSize iconSize = ShellImageSize.Large)
        {
            var shfi       = new SHFILEINFO();
            var hImageList = SHGetFileInfo(fileNameOrExtension, 0, ref shfi, shfiSz, SHGFI.SHGFI_SYSICONINDEX | (iconSize == ShellImageSize.Small ? SHGFI.SHGFI_SMALLICON : 0));

            if (hImageList == IntPtr.Zero)
            {
                return(null);
            }
            if (iconSize <= ShellImageSize.Small)
            {
                return(IconLocation.GetClonedIcon(ImageList_GetIcon(hImageList, shfi.iIcon, IMAGELISTDRAWFLAGS.ILD_TRANSPARENT)));
            }
            SHGetImageList((SHIL)iconSize, typeof(IImageList).GUID, out var il).ThrowIfFailed();
            return(IconLocation.GetClonedIcon(il.GetIcon(shfi.iIcon, IMAGELISTDRAWFLAGS.ILD_TRANSPARENT)));
        }
Esempio n. 2
0
        /// <summary>Gets the system icon for the given file name or extension.</summary>
        /// <param name="fileNameOrExtension">The file name or extension.</param>
        /// <param name="iconSize">Size of the icon.</param>
        /// <returns>An <see cref="Icon"/> instance if found; otherwise <see langword="null"/>.</returns>
        public static Icon GetSystemIcon(string fileNameOrExtension, ShellImageSize iconSize = ShellImageSize.Large)
        {
            var shfi = new SHFILEINFO();

            if (hSystemImageList.IsNull)
            {
                hSystemImageList = SHGetFileInfo(fileNameOrExtension, 0, ref shfi, SHFILEINFO.Size, SHGFI.SHGFI_SYSICONINDEX | (iconSize == ShellImageSize.Small ? SHGFI.SHGFI_SMALLICON : 0));
            }
            if (hSystemImageList.IsNull)
            {
                return(null);
            }
            if (iconSize <= ShellImageSize.Small)
            {
                return(ImageList_GetIcon(hSystemImageList, shfi.iIcon, IMAGELISTDRAWFLAGS.ILD_TRANSPARENT).ToIcon());
            }
            return(GetSystemIcon(shfi.iIcon, iconSize));
        }
Esempio n. 3
0
 /// <summary>Given an image list size, return the related size, in pixels, of that size defined on the system.</summary>
 /// <param name="imageListSize">Size of the image list.</param>
 /// <returns>Pixel size of corresponding system value.</returns>
 public static int SHILtoPixels(ShellImageSize imageListSize) => g_rgshil[imageListSize];
Esempio n. 4
0
 /// <summary>Gets the system icon for and index and size.</summary>
 /// <param name="index">The index of the system icon to retrieve.</param>
 /// <param name="iconSize">Size of the icon.</param>
 /// <returns>An <see cref="Icon"/> instance if found; otherwise <see langword="null"/>.</returns>
 public static SafeHICON GetSystemIconHandle(int index, ShellImageSize iconSize = ShellImageSize.Large)
 {
     SHGetImageList((SHIL)iconSize, typeof(IImageList).GUID, out var il).ThrowIfFailed();
     return(il.GetIcon(index, IMAGELISTDRAWFLAGS.ILD_TRANSPARENT));
 }
Esempio n. 5
0
 /// <summary>Gets the system icon for and index and size.</summary>
 /// <param name="index">The index of the system icon to retrieve.</param>
 /// <param name="iconSize">Size of the icon.</param>
 /// <returns>An <see cref="Icon"/> instance if found; otherwise <see langword="null"/>.</returns>
 public static Icon GetSystemIcon(int index, ShellImageSize iconSize = ShellImageSize.Large) => GetSystemIconHandle(index, iconSize)?.ToIcon();
Esempio n. 6
0
 /// <summary>Gets the system icon for and index and size.</summary>
 /// <param name="index">The index of the system icon to retrieve.</param>
 /// <param name="iconSize">Size of the icon.</param>
 /// <returns>An <see cref="SafeHICON"/> instance if found; otherwise <see langword="null"/>.</returns>
 public static SafeHICON GetSystemIcon(int index, ShellImageSize iconSize = ShellImageSize.Large) => GetSystemIconHandle(index, iconSize);
Esempio n. 7
0
 /// <summary>Given an image list size, return the related size, in pixels, of that size defined on the system.</summary>
 /// <param name="imageListSize">Size of the image list.</param>
 /// <returns>Pixel size of corresponding system value.</returns>
 public static int SHILtoPixels(ShellImageSize imageListSize) => ShellUtil.SHILToPixels((SHIL)imageListSize);