public static Icon GetIcon(int index, ShellImageListSize size) { IntPtr iconPtr = IntPtr.Zero; switch (size) { case ShellImageListSize.Small: iconPtr = NativeMethods.ComCtl32.ImageList_GetIcon(m_smallImageListHandle, index, NativeMethods.ILD_NORMAL); break; case ShellImageListSize.Large: iconPtr = NativeMethods.ComCtl32.ImageList_GetIcon(m_largeImageListHandle, index, NativeMethods.ILD_NORMAL); break; } if (iconPtr != IntPtr.Zero) { Icon icon = Icon.FromHandle(iconPtr); Icon retVal = (Icon)icon.Clone(); NativeMethods.User32.DestroyIcon(iconPtr); return(retVal); } else { return(null); } }
/// <summary> /// Gets the image list interface. /// </summary> /// <param name="imageListSize">Size of the image list.</param> /// <returns>The IImageList for the shell image list of the given size.</returns> public static IntPtr GetImageList(ShellImageListSize imageListSize) { // Do we have the image list? IImageList imageList; if (imageLists.TryGetValue(imageListSize, out imageList)) { return(GetImageListHandle(imageList)); } // We don't have the image list, create it. Shell32.SHGetImageList((int)imageListSize, ref Shell32.IID_IImageList, ref imageList); // Add it to the dictionary. imageLists.Add(imageListSize, imageList); // Return it. return(GetImageListHandle(imageList)); }
public static Icon GetIcon(int index, ShellImageListSize size) { IntPtr iconPtr = IntPtr.Zero; switch (size) { case ShellImageListSize.Small: iconPtr = NativeMethods.ComCtl32.ImageList_GetIcon(m_smallImageListHandle, index, NativeMethods.ILD_NORMAL); break; case ShellImageListSize.Large: iconPtr = NativeMethods.ComCtl32.ImageList_GetIcon(m_largeImageListHandle, index, NativeMethods.ILD_NORMAL); break; } if (iconPtr != IntPtr.Zero) { Icon icon = Icon.FromHandle(iconPtr); Icon retVal = (Icon)icon.Clone(); NativeMethods.User32.DestroyIcon(iconPtr); return retVal; } else return null; }
/// <summary> /// Creates a SystemImageList with the specified size /// </summary> /// <param name="size">Size of System ImageList</param> public ShellImageList(ShellImageListSize size) { this.size = size; Create(); }
/// <summary> /// Gets the image list interface. /// </summary> /// <param name="imageListSize">Size of the image list.</param> /// <returns>The IImageList for the shell image list of the given size.</returns> public static IntPtr GetImageList(ShellImageListSize imageListSize) { // Do we have the image list? IImageList imageList; if (imageLists.TryGetValue(imageListSize, out imageList)) return GetImageListHandle(imageList); // We don't have the image list, create it. Shell32.SHGetImageList((int)imageListSize, ref Shell32.IID_IImageList, ref imageList); // Add it to the dictionary. imageLists.Add(imageListSize, imageList); // Return it. return GetImageListHandle(imageList); }