Skip to content

Instantly share code, notes, and snippets.

@abfo
Created September 30, 2018 17:14
Show Gist options
  • Select an option

  • Save abfo/3af4c811b4bdd5ea1793c66297a8b737 to your computer and use it in GitHub Desktop.

Select an option

Save abfo/3af4c811b4bdd5ea1793c66297a8b737 to your computer and use it in GitHub Desktop.
BitmapSource shieldSource = null;
if (Environment.OSVersion.Version.Major >= 6)
{
SHSTOCKICONINFO sii = new SHSTOCKICONINFO();
sii.cbSize = (UInt32) Marshal.SizeOf(typeof(SHSTOCKICONINFO));
Marshal.ThrowExceptionForHR(SHGetStockIconInfo(SHSTOCKICONID.SIID_SHIELD,
SHGSI.SHGSI_ICON | SHGSI.SHGSI_SMALLICON,
ref sii));
shieldSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
sii.hIcon,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
DestroyIcon(sii.hIcon);
}
else
{
shieldSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
System.Drawing.SystemIcons.Shield.Handle,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment