protected internal static BitmapSource GetBitmapSource(StockIconIdentifier identifier, StockIconOptions flags)
        {
            BitmapSource bitmapSource = (BitmapSource)InteropHelper.MakeImage(identifier, StockIconOptions.Handle | flags);

            bitmapSource.Freeze();
            return(bitmapSource);
        }
Exemple #2
0
		/// <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;
		}
Exemple #3
0
        /// <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);
            }
        }
Exemple #4
0
 /// <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;
 }
Exemple #5
0
        private static ImageSource GetImageSource(StockIconIdentifier identifier, StockIconOptions flags)
        {
            ImageSource imageSource = MakeImage(identifier, StockIconOptions.Handle | flags);

            imageSource.Freeze();

            return(imageSource);
        }
Exemple #6
0
 /// <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;
 }
Exemple #7
0
 /// <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;
 }
        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;
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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;
 }
Exemple #14
0
        /// <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);
        }
Exemple #15
0
        /// <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);
        }
Exemple #16
0
        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);
        }
Exemple #17
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);
        }
Exemple #18
0
        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);
        }
Exemple #19
0
 /// <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;
 }
Exemple #20
0
 /// <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)
 {
 }
Exemple #21
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;
 }
Exemple #22
0
 private static extern int SHGetStockIconInfo(StockIconIdentifier identifier, StockIconOptions flags, ref StockIconInfo info);
Exemple #23
0
 /// <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;
 }
        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);
Exemple #31
0
 /// <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;
 }
Exemple #32
0
 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;
        }
Exemple #35
0
 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;
        }
Exemple #37
0
 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);
 public static extern HResult SHGetStockIconInfo(
     StockIconIdentifier identifier,
     StockIconOptions flags,
     ref StockIconInfo info);