Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SHGetStockIconInfo (shell32)
 
.
Summary
Retrieves information about a stock icon

C# Signature:

[DllImport("Shell32.dll", SetLastError = false)]
public static extern Int32 SHGetStockIconInfo(SHSTOCKICONID siid, SHGSI uFlags, ref SHSTOCKICONINFO psii);

VB Signature:

Declare Function SHGetStockIconInfo Lib "Shell32.dll" (TODO) As TODO

User-Defined Types:

See SHSTOCKICONID, SHGSI and SHSTOCKICONINFO.

Alternative Managed API:

System.Drawing.SystemIcons, although note that not all icons are included and at least the Shield icon is incorrect on Win 7 / Win 2008.

Notes:

SHGetStockIconInfo is supported on Windows Vista / 2008 or later.

Tips & Tricks:

Please add some!

Sample Code:

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));

// do something with sii.hIcon

button4.Image = Icon.FromHandle(sii.hIcon).ToBitmap();

DestroyIcon(sii.hIcon);

Sample Code:

    Public Shared Function GetShildIcon(iconType As SHSTOCKICONID) As IntPtr
    Dim sii As New SHSTOCKICONINFO()
    sii.cbSize = Marshal.SizeOf(GetType(SHSTOCKICONINFO))

    If SHGetStockIconInfo(iconType, SHGSI.SHGSI_ICON Or SHGSI.SHGSI_SMALLICON, sii) = 0 Then
        Return sii.hIcon
    End If
    Return IntPtr.Zero
    End Function

    Dim hIcon As IntPtr = GetShildIcon(SHSTOCKICONID.SIID_SHIELD)
    If hIcon <> IntPtr.Zero Then
        Me.Icon = Icon.FromHandle(hIcon)
        DestroyIcon(hIcon)
    End If

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions