示例#1
0
            public static Icon GetStockIcon(SIID iconId, bool large)
            {
                var info = new SHSTOCKICONINFO();

                info.cbSize = (uint)Marshal.SizeOf(info);
                var result = SHGetStockIconInfo((uint)iconId, (uint)(SHGSI.ICON | (large ? SHGSI.LARGEICON : SHGSI.SMALLICON)), ref info);

                if (result != 0)
                {
                    throw new Win32Exception(result);
                }

                var icon = (Icon)Icon.FromHandle(info.hIcon).Clone(); // Get a copy that doesn't use the original handle

                DestroyIcon(info.hIcon);                              // Clean up native icon to prevent resource leak

                return(icon);
            }
示例#2
0
 public static extern int SHGetStockIconInfo(SIID siid, SHGSI uFlags, ref SHSTOCKICONINFO psii);
示例#3
0
 public static ImageSource GetImageSource(SIID iconId, bool large = false)
 {
     using var icon = StockIcons.GetStockIcon(iconId, large);
     return(Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
 }