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 new StockIcon instance with the specified identifer and options. /// </summary> /// <param name="id">A value that identifies the icon represented by this instance.</param> /// <param name="size">A value that indicates the size of the stock icon.</param> /// <param name="isLinkOverlay">A bool value that indicates whether the icon has a link overlay.</param> /// <param name="isSelected">A bool value that indicates whether the icon is in a selected state.</param> public StockIcon(StockIconIdentifier id, StockIconSize size, bool isLinkOverlay, bool isSelected) { identifier = id; linkOverlay = isLinkOverlay; selected = isSelected; currentSize = size; invalidateIcon = true; }
/// <summary> /// Returns the existing stock icon from the internal cache, or creates a new one /// based on the current settings if it's not in the cache. /// </summary> /// <param name="stockIconIdentifier">Unique identifier for the requested stock icon</param> /// <returns>Stock Icon based on the identifier given (either from the cache or created new)</returns> private StockIcon GetStockIcon(StockIconIdentifier stockIconIdentifier) { // Check the cache first if (stockIconCache[stockIconIdentifier] != null) { return(stockIconCache[stockIconIdentifier]); } else { // Create a new icon based on our default settings StockIcon icon = new StockIcon(stockIconIdentifier, defaultSize, isLinkOverlay, isSelected); try { // Add it to the cache stockIconCache[stockIconIdentifier] = icon; } catch { icon.Dispose(); throw; } // Return return(icon); } }
/// <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) { 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); }
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); }
/// <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); }
/// <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); }
private ICollection <StockIcon> GetAllStockIcons() { // Create a list of stock Identifiers StockIconIdentifier[] ids = new StockIconIdentifier[stockIconCache.Count]; stockIconCache.Keys.CopyTo(ids, 0); // For each identifier, if our cache is null, create a new stock icon foreach (StockIconIdentifier id in ids) { if (stockIconCache[id] == null) { GetStockIcon(id); } } // return the list of stock icons return(stockIconCache.Values); }
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); }
/// <summary> /// Creates a new StockIcon instance with the specified identifer, default size /// and no link overlay or selected states. /// </summary> /// <param name="id">A value that identifies the icon represented by this instance.</param> public StockIcon(StockIconIdentifier id) { identifier = id; invalidateIcon = true; }
/// <summary> /// Creates a new StockIcon instance with the specified identifer. /// </summary> /// <param name="identifier"> /// A value that identifies the icon represented by this instance. /// </param> public StockIcon(StockIconIdentifier identifier) : this(identifier, 0) { }
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; }
private static extern int SHGetStockIconInfo(StockIconIdentifier identifier, StockIconOptions flags, ref StockIconInfo info);
private ICollection<StockIcon> GetAllStockIcons() { // Create a list of stock Identifiers StockIconIdentifier[] ids = new StockIconIdentifier[stockIconCache.Count]; stockIconCache.Keys.CopyTo(ids, 0); // For each identifier, if our cache is null, create a new stock icon foreach (StockIconIdentifier id in ids) { if (stockIconCache[id] == null) GetStockIcon(id); } // return the list of stock icons return stockIconCache.Values; }
/// <summary> /// Returns the existing stock icon from the internal cache, or creates a new one /// based on the current settings if it's not in the cache. /// </summary> /// <param name="stockIconIdentifier">Unique identifier for the requested stock icon</param> /// <returns>Stock Icon based on the identifier given (either from the cache or created new)</returns> private StockIcon GetStockIcon(StockIconIdentifier stockIconIdentifier) { // Check the cache first if (stockIconCache[stockIconIdentifier] != null) return stockIconCache[stockIconIdentifier]; else { // Create a new icon based on our default settings StockIcon icon = new StockIcon(stockIconIdentifier, defaultSize, isLinkOverlay, isSelected); try { // Add it to the cache stockIconCache[stockIconIdentifier] = icon; } catch { icon.Dispose(); throw; } // Return return icon; } }
public StockIcon(StockIconIdentifier identifier) : this(identifier, 0) { }
public static BitmapSource GetBitmapSource(StockIconIdentifier identifier) { return(StockIcon.GetBitmapSource(identifier, 0)); }
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; }
public static BitmapSource GetBitmapSource(StockIconIdentifier identifier) { return StockIcon.GetBitmapSource(identifier, 0); }
internal static extern int SHGetStockIconInfo( StockIconIdentifier identifier, StockIconOptions flags, ref SafeNativeMethods.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; }
public static BitmapSource GetBitmapSource(StockIconIdentifier identifier) => StockIcon.GetBitmapSource(identifier, 0);
public static extern HResult 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); if (bitmapSource != null) bitmapSource.Freeze(); return bitmapSource; }
internal static extern HRESULT SHGetStockIconInfo( StockIconIdentifier identifier, StockIconOptions flags, ref StockIconInfo info);
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; }
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 StockIconInfo info);