private BitmapSource GetBitmapSource(ShellApi.StockIconIdentifier identifier) { var bitmapSource = (BitmapSource)MakeImage(identifier, ShellApi.StockIconOptions.Handle | _flags); bitmapSource.Freeze(); return(bitmapSource); }
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); }
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); }
internal static extern int SHGetStockIconInfo(ShellApi.StockIconIdentifier identifier, ShellApi.StockIconOptions flags, ref ShellApi.StockIconInfo info);