internal static BitmapSource GetImage(NativeStockIcon icon, NativeStockIconOptions options) { options |= NativeStockIconOptions.Handle; StockIconInfo info = new StockIconInfo(); info.StructureSize = (uint)Marshal.SizeOf(typeof(StockIconInfo)); int hresult = SHGetStockIconInfo(icon, options, ref info); if (hresult < 0) { throw new COMException("SHGetStockIconInfo failed", hresult); } BitmapSource bitmap; try { bitmap = Imaging.CreateBitmapSourceFromHIcon(info.Handle, Int32Rect.Empty, null); } finally { DestroyIcon(info.Handle); } return(bitmap); }
object RenderStockIcon(string id, NativeStockIconOptions options) { if (Environment.OSVersion.Version.Major <= 5) { throw new NotImplementedException(); } switch (id) { case StockIconId.Add: using (var s = typeof(ImageHandler).Assembly.GetManifestResourceStream("Xwt.WPF.icons.add-16.png")) return(LoadFromStream(s)); case StockIconId.Remove: using (var s = typeof(ImageHandler).Assembly.GetManifestResourceStream("Xwt.WPF.icons.remove-16.png")) return(LoadFromStream(s)); case StockIconId.Error: return(new WpfImage(NativeMethods.GetImage(NativeStockIcon.Error, options))); case StockIconId.Information: return(new WpfImage(NativeMethods.GetImage(NativeStockIcon.Info, options))); case StockIconId.OrientationLandscape: case StockIconId.OrientationPortrait: return(new WpfImage(NativeMethods.GetImage(NativeStockIcon.Help, options))); //throw new NotImplementedException(); case StockIconId.Question: return(new WpfImage(NativeMethods.GetImage(NativeStockIcon.Help, options))); case StockIconId.Warning: return(new WpfImage(NativeMethods.GetImage(NativeStockIcon.Warning, options))); case StockIconId.Zoom100: case StockIconId.ZoomFit: case StockIconId.ZoomIn: case StockIconId.ZoomOut: return(new WpfImage(NativeMethods.GetImage(NativeStockIcon.Find, options))); default: throw new ArgumentException("Unknown icon id", "id"); } }
internal static BitmapSource GetImage(NativeStockIcon icon, NativeStockIconOptions options) { options |= NativeStockIconOptions.Handle; StockIconInfo info = new StockIconInfo(); info.StructureSize = (uint) Marshal.SizeOf (typeof (StockIconInfo)); int hresult = SHGetStockIconInfo (icon, options, ref info); if (hresult < 0) throw new COMException ("SHGetStockIconInfo failed", hresult); BitmapSource bitmap; try { bitmap = Imaging.CreateBitmapSourceFromHIcon (info.Handle, Int32Rect.Empty, null); } finally { DestroyIcon (info.Handle); } return bitmap; }
object RenderStockIcon(string id, NativeStockIconOptions options) { if (Environment.OSVersion.Version.Major <= 5) throw new NotImplementedException (); switch (id) { case StockIconId.Add: using (var s = typeof (ImageHandler).Assembly.GetManifestResourceStream ("Xwt.WPF.icons.add-16.png")) return LoadFromStream (s); case StockIconId.Remove: using (var s = typeof (ImageHandler).Assembly.GetManifestResourceStream ("Xwt.WPF.icons.remove-16.png")) return LoadFromStream (s); case StockIconId.Error: return new WpfImage (NativeMethods.GetImage (NativeStockIcon.Error, options)); case StockIconId.Information: return new WpfImage (NativeMethods.GetImage (NativeStockIcon.Info, options)); case StockIconId.OrientationLandscape: case StockIconId.OrientationPortrait: return new WpfImage (NativeMethods.GetImage (NativeStockIcon.Help, options)); //throw new NotImplementedException(); case StockIconId.Question: return new WpfImage (NativeMethods.GetImage (NativeStockIcon.Help, options)); case StockIconId.Warning: return new WpfImage (NativeMethods.GetImage (NativeStockIcon.Warning, options)); case StockIconId.Zoom100: case StockIconId.ZoomFit: case StockIconId.ZoomIn: case StockIconId.ZoomOut: return new WpfImage (NativeMethods.GetImage (NativeStockIcon.Find, options)); default: throw new ArgumentException ("Unknown icon id", "id"); } }
static extern int SHGetStockIconInfo(NativeStockIcon icon, NativeStockIconOptions options, ref StockIconInfo info);