private static uint ToStockIconFlags(IconSize size, StockIconOptions options) { uint flags = NativeMethods.SHGSI_ICON; switch (size) { case IconSize.Large: flags |= NativeMethods.SHGSI_LARGEICON; break; case IconSize.Small: flags |= NativeMethods.SHGSI_SMALLICON; break; case IconSize.ShellSize: flags |= NativeMethods.SHGSI_SHELLICONSIZE; break; } if ((options & StockIconOptions.LinkOverlay) == StockIconOptions.LinkOverlay) { flags |= NativeMethods.SHGSI_LINKOVERLAY; } if ((options & StockIconOptions.Selected) == StockIconOptions.Selected) { flags |= NativeMethods.SHGSI_SELECTED; } return(flags); }
/// <summary> /// Creates a new StockIcon instance with the /// specified /// <see cref="Microsoft.SDK.Samples.VistaBridge.Library.StockIcons.StockIconIdentifier"/> and <see cref="Microsoft.SDK.Samples.VistaBridge.Library.StockIcons.StockIconOptions"/> values. /// </summary> /// <param name="identifier"> /// A value that identifies the icon represented by this instance. /// </param> /// <param name="options"> /// A set of values that controls the visual /// representation of the icon. /// </param> public StockIcon(StockIconIdentifier identifier, StockIconOptions options) { Identifier = identifier; Selected = (options & StockIconOptions.Selected) == StockIconOptions.Selected; LinkOverlay = (options & StockIconOptions.LinkOverlay) == StockIconOptions.LinkOverlay; ShellSize = (options & StockIconOptions.ShellSize) == StockIconOptions.ShellSize; Small = (options & StockIconOptions.Small) == StockIconOptions.Small; }
private static ImageSource GetImageSource(StockIconIdentifier identifier, StockIconOptions flags) { ImageSource imageSource = MakeImage(identifier, StockIconOptions.Handle | flags); imageSource.Freeze(); return(imageSource); }
internal static ImageSource MakeImage(StockIconIdentifier identifier, StockIconOptions flags) { IntPtr iconHandle = GetIcon(identifier, flags); ImageSource imageSource; try { imageSource = InteropImaging.CreateBitmapSourceFromHIcon(iconHandle, Int32Rect.Empty, null); } finally { DestroyIcon(iconHandle); } return(imageSource); }
internal static IntPtr GetIcon(StockIconIdentifier identifier, StockIconOptions flags) { SafeNativeMethods.StockIconInfo info = new SafeNativeMethods.StockIconInfo(); info.StuctureSize = (UInt32)System.Runtime.InteropServices.Marshal.SizeOf(typeof(SafeNativeMethods.StockIconInfo)); int hResult = UnsafeNativeMethods.SHGetStockIconInfo(identifier, flags, ref info); if (hResult != 0) throw new System.ComponentModel.Win32Exception("SHGetStockIconInfo execution failure " + hResult.ToString()); return info.Handle; }
private static IntPtr GetIcon(StockIconIdentifier identifier, StockIconOptions flags) { StockIconInfo info = new StockIconInfo(); info.StructureSize = (UInt32)Marshal.SizeOf(typeof(StockIconInfo)); int hResult = SHGetStockIconInfo(identifier, flags, ref info); if (hResult < 0) { throw new COMException("SHGetStockIconInfo", hResult); } return(info.Handle); }
internal static IntPtr GetIcon(StockIconIdentifier identifier, StockIconOptions flags) { StockIconInfo info = new StockIconInfo() { StuctureSize = (uint)Marshal.SizeOf(typeof(StockIconInfo)) }; int hResult = SHGetStockIconInfo(identifier, flags, ref info); if (hResult < 0) { throw new COMException("SHGetStockIconInfo execution failure", hResult); } return(info.Handle); }
internal static IntPtr GetIcon(StockIconIdentifier identifier, StockIconOptions flags) { SafeNativeMethods.StockIconInfo info = new SafeNativeMethods.StockIconInfo(); info.StuctureSize = (UInt32)System.Runtime.InteropServices.Marshal.SizeOf(typeof(SafeNativeMethods.StockIconInfo)); int hResult = UnsafeNativeMethods.SHGetStockIconInfo(identifier, flags, ref info); if (hResult != 0) { throw new System.ComponentModel.Win32Exception("SHGetStockIconInfo execution failure " + hResult.ToString()); } return(info.Handle); }
/// <summary> /// Gets the specified icon. /// </summary> /// <param name="identifier">The StockIdentifier enumeration value that /// that identifies the icon to retrieve. /// </param> /// <param name="flags"> /// The StockIconOptions enumeration values that control /// the visual representation of the icon. /// </param> /// <returns></returns> internal static ImageSource MakeImage( StockIconIdentifier identifier, StockIconOptions flags) { IntPtr iconHandle = GetIcon(identifier, flags); ImageSource imageSource; try { imageSource = Imaging.CreateBitmapSourceFromHIcon(iconHandle, System.Windows.Int32Rect.Empty, null); } finally { UnsafeNativeMethods.DestroyIcon(iconHandle); } return imageSource; }
/// <summary> /// Gets the specified icon. /// </summary> /// <param name="identifier">The StockIdentifier enumeration value that /// that identifies the icon to retrieve. /// </param> /// <param name="flags"> /// The StockIconOptions enumeration values that control /// the visual representation of the icon. /// </param> /// <returns></returns> internal static ImageSource MakeImage( StockIconIdentifier identifier, StockIconOptions flags) { IntPtr iconHandle = GetIcon(identifier, flags); ImageSource imageSource; try { imageSource = Imaging.CreateBitmapSourceFromHIcon(iconHandle, System.Windows.Int32Rect.Empty, null); } finally { UnsafeNativeMethods.DestroyIcon(iconHandle); } return(imageSource); }
internal static ImageSource MakeImage(StockIconIdentifier identifier, StockIconOptions flags) { ImageSource imageSource = null; IntPtr iconHandle = IntPtr.Zero; try { iconHandle = GetIcon(identifier, flags); imageSource = InteropImaging.CreateBitmapSourceFromHIcon(iconHandle, Int32Rect.Empty, null); } catch { // ignore exception (this will throw on Windows XP which doesn't have an SHGetStockIconInfo) } finally { DestroyIcon(iconHandle); } return(imageSource); }
static int ComputeUniqueValue(StockIconIdentifier identifier, StockIconOptions flags) { int value = checked (((int)identifier) << 4); if ((flags & StockIconOptions.Selected) == StockIconOptions.Selected) { value += 8; } if ((flags & StockIconOptions.Small) == StockIconOptions.Small) { value += 4; } if ((flags & StockIconOptions.LinkOverlay) == StockIconOptions.LinkOverlay) { value += 2; } if ((flags & StockIconOptions.ShellSize) == StockIconOptions.ShellSize) { value += 1; } return(value); }
internal static extern int SHGetStockIconInfo( StockIconIdentifier identifier, StockIconOptions flags, ref SafeNativeMethods.StockIconInfo info);
internal static ImageSource MakeImage(StockIconIdentifier identifier, StockIconOptions flags) { IntPtr iconHandle = GetIcon(identifier, flags); ImageSource imageSource; try { imageSource = InteropImaging.CreateBitmapSourceFromHIcon(iconHandle, Int32Rect.Empty, null); } finally { DestroyIcon(iconHandle); } return imageSource; }
public static Icon GetStockIcon(StockIcon stockIcon, IconSize size = IconSize.Large, StockIconOptions options = 0) { var flags = ToStockIconFlags(size, options); var sii = new UnsafeNativeMethods.SHSTOCKICONINFO(); sii.cbSize = UnsafeNativeMethods.SHSTOCKICONINFO.Sizeof(); int hr = UnsafeNativeMethods.SHGetStockIconInfo((int)stockIcon, flags, ref sii); if (hr != 0) { throw new COMException("SHGetStockIconInfo failed.", hr); } if (sii.hIcon == IntPtr.Zero) { throw new NotSupportedException("The stock icon is not supported by the running OS."); } return(HIconToIcon(sii.hIcon)); }
private static extern int SHGetStockIconInfo(StockIconIdentifier identifier, StockIconOptions flags, ref StockIconInfo info);
protected internal static BitmapSource GetBitmapSource(StockIconIdentifier identifier, StockIconOptions flags) { BitmapSource bitmapSource = (BitmapSource)InteropHelper.MakeImage(identifier, StockIconOptions.Handle | flags); bitmapSource.Freeze(); return(bitmapSource); }
/// <summary> /// Creates a <see cref="System.Windows.Media.Imaging.BitmapSource"/> object for the specified icon. /// </summary> /// <param name="identifier"> /// The identifier for the icon represented by this instance. /// </param> /// <param name="options"> /// Settings that control the visual representation of the icon. /// </param> /// <returns>A <see cref="System.Windows.Media.Imaging.BitmapSource"/> object that represents the specified icon.</returns> protected internal static BitmapSource GetBitmapSource(StockIconIdentifier identifier, StockIconOptions options) { BitmapSource bitmapSource; int uniqueValue = ComputeUniqueValue(identifier, options); if (!_cache.TryGetValue(uniqueValue, out bitmapSource)) { bitmapSource = (BitmapSource)StockIconHelper.MakeImage(identifier, StockIconOptions.Handle | options); bitmapSource.Freeze(); _cache[uniqueValue] = bitmapSource; } else { System.Diagnostics.Debug.WriteLine("Found the BitmapSource for " + identifier.ToString() + " in the cache!"); } return bitmapSource; }
static int ComputeUniqueValue(StockIconIdentifier identifier, StockIconOptions flags) { int value = checked(((int)identifier) << 4); if ((flags & StockIconOptions.Selected) == StockIconOptions.Selected) value += 8; if ((flags & StockIconOptions.Small) == StockIconOptions.Small) value += 4; if ((flags & StockIconOptions.LinkOverlay) == StockIconOptions.LinkOverlay) value += 2; if ((flags & StockIconOptions.ShellSize) == StockIconOptions.ShellSize) value += 1; return value; }
internal static ImageSource MakeImage(StockIconIdentifier identifier, StockIconOptions flags) { ImageSource imageSource = null; IntPtr iconHandle = IntPtr.Zero; try { iconHandle = GetIcon(identifier, flags); imageSource = InteropImaging.CreateBitmapSourceFromHIcon(iconHandle, Int32Rect.Empty, null); } catch { // ignore exception (this will throw on Windows XP which doesn't have an SHGetStockIconInfo) } finally { DestroyIcon(iconHandle); } return imageSource; }
protected internal static BitmapSource GetBitmapSource(StockIconIdentifier identifier, StockIconOptions flags) { BitmapSource bitmapSource = (BitmapSource)InteropHelper.MakeImage(identifier, StockIconOptions.Handle | flags); if (bitmapSource != null) bitmapSource.Freeze(); return bitmapSource; }
public static extern HResult SHGetStockIconInfo( StockIconIdentifier identifier, StockIconOptions flags, ref StockIconInfo info);
/// <summary> /// Creates a <see cref="System.Windows.Media.Imaging.BitmapSource"/> object for the specified icon. /// </summary> /// <param name="identifier"> /// The identifier for the icon represented by this instance. /// </param> /// <param name="options"> /// Settings that control the visual representation of the icon. /// </param> /// <returns>A <see cref="System.Windows.Media.Imaging.BitmapSource"/> object that represents the specified icon.</returns> protected internal static BitmapSource GetBitmapSource(StockIconIdentifier identifier, StockIconOptions options) { BitmapSource bitmapSource; int uniqueValue = ComputeUniqueValue(identifier, options); if (!_cache.TryGetValue(uniqueValue, out bitmapSource)) { bitmapSource = (BitmapSource)StockIconHelper.MakeImage(identifier, StockIconOptions.Handle | options); bitmapSource.Freeze(); _cache[uniqueValue] = bitmapSource; } else { System.Diagnostics.Debug.WriteLine("Found the BitmapSource for " + identifier.ToString() + " in the cache!"); } return(bitmapSource); }
internal static IntPtr GetIcon(StockIconIdentifier identifier, StockIconOptions flags) { StockIconInfo info = new StockIconInfo(); info.StuctureSize = (UInt32)Marshal.SizeOf(typeof(StockIconInfo)); int hResult = SHGetStockIconInfo(identifier, flags, ref info); if (hResult < 0) throw new COMException("SHGetStockIconInfo execution failure", hResult); return info.Handle; }
internal static extern HRESULT SHGetStockIconInfo( StockIconIdentifier identifier, StockIconOptions flags, ref StockIconInfo info);
internal static extern int SHGetStockIconInfo(StockIconIdentifier identifier, StockIconOptions flags, ref StockIconInfo info);