public IconLocation(string fileName, int index, GILI iconFlags, SHIL size) { FileName = string.Intern(Path.GetFullPath(fileName)); Index = index; IconFlags = iconFlags; Size = size; }
public static IImageList SHGetImageList(SHIL iImageList) { object ppv; SHGetImageList(iImageList, typeof(IImageList).GUID, out ppv); return((IImageList)ppv); }
public static ImageSource GetIcon(string path, SHIL size) { IntPtr result = IntPtr.Zero; SHFILEINFO shFileInfo = new SHFILEINFO(); if (path.StartsWith(".") || path.StartsWith(@"\\")) { result = SHGetFileInfo(path, FileAttributes.Normal, ref shFileInfo, Marshal.SizeOf(shFileInfo), SHGFI.SHGFI_SYSICONINDEX | SHGFI.SHGFI_USEFILEATTRIBUTES); } else { PIDL pidl = ILCreateFromPath(path); result = SHGetFileInfo(pidl, FileAttributes.Normal, ref shFileInfo, Marshal.SizeOf(shFileInfo), SHGFI.SHGFI_SYSICONINDEX | SHGFI.SHGFI_PIDL); } if (result == IntPtr.Zero) { return(null); } SHGetImageList(size, ImageListId, out IImageList iImageList); SafeHICON hIcon = iImageList.GetIcon(shFileInfo.iIcon, IMAGELISTDRAWFLAGS.ILD_IMAGE); ImageSource imageSource = hIcon.ToBitmapSource(); imageSource.Freeze(); DestroyIcon(hIcon); return(imageSource); }
private ImageSource GetIcon(SHIL iconSize, GILI iconAttrs) { int iconIndex = GetIconIndex(iconAttrs); return(iconIndex != UnindexableIconIndex ? _tree.IconList.GetIconByIndex(iconSize, iconIndex) : _tree.IconList.ExtractIcon(ParentShellFolder, _pidl, iconSize, iconAttrs)); }
public static IImageList SHGetImageList(SHIL iImageList) { var iid = typeof(IImageList).GUID; object imageList; int hr = SHGetImageList(iImageList, ref iid, out imageList); return(hr >= 0 ? (IImageList)imageList : null); }
/// <summary> /// Associates a SysImageList with a ListView control /// </summary> /// <param name="listView">ListView control to associate ImageList with</param> /// <param name="Usage">State, Group, Normal, Small /// false=Set Small Icon List</param> /// <param name="IIlSize">Size of Images</param> public static void SetListViewImageList(ListView listView, LVSIL Usage, SHIL IIlSize) { Initializer(); int wParam = (int)Usage; IntPtr HImageList = m_lgImgList; if (IIlSize == SHIL.Small) { HImageList = m_smImgList; } else if (IIlSize == SHIL.Jumbo) { HImageList = m_jumboImgList; } else if (IIlSize == SHIL.XLarge) { HImageList = m_xlgImgList; } User32.SendMessage(listView.Handle, MSG.LVM_SETIMAGELIST, wParam, HImageList); }
public static Bitmap GetJumboIcon(string filePath) { SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hImg = SHGetFileInfo(filePath, 0, out shinfo, (uint)Marshal.SizeOf(typeof(SHFILEINFO)), SHGFI.SHGFI_SYSICONINDEX); SHIL currentShil = SHIL.SHIL_JUMBO; IImageList imgList = null; int result = SHGetImageList(currentShil, ref IID_IImageList, out imgList); IntPtr hIcon = IntPtr.Zero; imgList.GetIcon(shinfo.iIcon, (int)ImageListDrawItemConstants.ILD_TRANSPARENT, ref hIcon); Icon icon = Icon.FromHandle(hIcon); Bitmap bmp = icon.ToBitmap(); return(bmp); //bmp.Save("C:/Users/Christian/Desktop/img.png", System.Drawing.Imaging.ImageFormat.Png); }
private static int IconSizeToPixels(SHIL iconSize) { // TODO Properly calculate icon size using GetSystemMetrics switch (iconSize) { case SHIL.SMALL: case SHIL.SYSSMALL: return(16); case SHIL.LARGE: return(32); case SHIL.EXTRALARGE: return(48); case SHIL.JUMBO: return(256); default: throw new ArgumentOutOfRangeException("iconSize"); } }
private static extern int SHGetImageList(SHIL iImageList, ref Guid iid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] out object imageList);
public ImageSource GetIconByIndex(SHIL iconSize, int index) { return(index >= 0 ? GetImageList(iconSize).GetIconImageSource(index) : null); }
public static extern int SHGetImageList(SHIL iImageList, ref Guid riid, out IntPtr ppv);
public ImageSource ExtractIcon(NativeShellFolder shellFolder, PIDLIST pidl, SHIL iconSize, GILI iconFlags) { return(ExtractIcon(shellFolder, pidl, IconSizeToPixels(iconSize), iconFlags)); }
private ShellImageList GetImageList(SHIL iconSize) { return(_imageLists.GetOrAdd(iconSize, () => new ShellImageList(iconSize))); }
public ShellImageList(SHIL iconSize) { _imageList = new NativeImageList(Native.SHGetImageList(iconSize)); _imageSourceCache = new IndexDictionary <ImageSource>(); }
private static extern int SHGetImageList(SHIL iImageList, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);
public ImageSource GetIcon(NativeShellIcon shellIcon, PIDLIST pidl, SHIL iconSize, GILI iconFlags) { return(GetIconByIndex(iconSize, GetIconIndex(shellIcon, pidl, iconFlags))); }
public ImageSource GetIconOverlay(NativeShellIconOverlay shellIconOverlay, PIDLIST pidl, SHIL iconSize) { return(GetIconByIndex(iconSize, GetIconOverlayIndex(shellIconOverlay, pidl))); }
public extern static int SHGetImageList(SHIL iImageList, ref Guid riid, out IImageList ppv);
private ImageSource GetIconOverlay(SHIL iconSize) { return(_tree.IconList.GetIconByIndex(iconSize, GetIconOverlayIndex())); }