Example #1
0
        private BitmapSource GetBitmapSource(ShellApi.StockIconIdentifier identifier)
        {
            var bitmapSource = (BitmapSource)MakeImage(identifier, ShellApi.StockIconOptions.Handle | _flags);

            bitmapSource.Freeze();
            return(bitmapSource);
        }
Example #2
0
        private static IntPtr GetIcon(ShellApi.StockIconIdentifier identifier, ShellApi.StockIconOptions flags)
        {
            var info = new ShellApi.StockIconInfo
            {
                StuctureSize = (UInt32)Marshal.SizeOf(typeof(ShellApi.StockIconInfo))
            };
            var hResult = Shell32.SHGetStockIconInfo(identifier, flags, ref info);

            if (hResult < 0)
            {
                throw new COMException("SHGetStockIconInfo execution failure", hResult);
            }
            return(info.Handle);
        }
Example #3
0
        private static ImageSource MakeImage(ShellApi.StockIconIdentifier identifier, ShellApi.StockIconOptions flags)
        {
            var         iconHandle = GetIcon(identifier, flags);
            ImageSource imageSource;

            try
            {
                imageSource = Imaging.CreateBitmapSourceFromHIcon(iconHandle, Int32Rect.Empty, null);
            }
            finally
            {
                User32.DestroyIcon(iconHandle);
            }
            return(imageSource);
        }
Example #4
0
 internal static extern int SHGetStockIconInfo(ShellApi.StockIconIdentifier identifier,
                                               ShellApi.StockIconOptions flags, ref ShellApi.StockIconInfo info);