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

Shell_NotifyIcon (shell32)
 
.
Summary

Sends a message to the taskbar's status area.

C# Signature:

    [DllImport("shell32.dll", CharSet = CharSet.Unicode)]
    private static extern bool Shell_NotifyIcon(uint message, ref NOTIFYICONDATA data);

User-Defined Types:

NOTIFYICONDATA

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Minimum supported client: Windows XP [desktop apps only]

Minimum supported server: Windows 2000 Server [desktop apps only]

Tips & Tricks:

Please add some!

Sample Code:

    var nid = new NOTIFYICONDATA
    {
        cbSize = Marshal.SizeOf(typeof(NOTIFYICONDATA)),
        hWnd = form.Handle,
        uID = 0,
        uFlags = NIF_ICON | NIF_TIP | NIF_SHOWTIP,
        hIcon = (icon == null ? form.Icon.Handle : icon.Handle),
        szTip = tip,
        uTimeoutOrVersion = NOTIFYICON_VERSION_4
    };
    Shell_NotifyIcon(NIM_SETVERSION, ref nid);
    Shell_NotifyIcon(NIM_ADD, ref nid);
    TrayIconID = nid.uID;

    [DllImport("shell32.dll", CharSet = CharSet.Unicode)]
    private static extern bool Shell_NotifyIcon(uint message, ref NOTIFYICONDATA data);

    private const uint NIM_ADD = 0x00;
    private const uint NIM_MODIFY = 0x01;
    private const uint NIM_DELETE = 0x02;
    private const uint NIM_SETFOCUS = 0x03;
    private const uint NIM_SETVERSION = 0x04;

    private const int NIF_MESSAGE = 0x01;
    private const int NIF_ICON = 0x02;
    private const int NIF_TIP = 0x04;
    private const int NIF_STATE = 0x08;
    private const int NIF_INFO = 0x10;
    private const int NIF_GUID = 0x20;
    private const int NIF_REALTIME = 0x40;
    private const int NIF_SHOWTIP = 0x80;

    private const int NOTIFYICON_VERSION_4 = 4;

    private const int NIIF_NONE = 0x00;
    private const int NIIF_INFO = 0x01;
    private const int NIIF_WARNING = 0x02;
    private const int NIIF_ERROR = 0x03;
    private const int NIIF_USER = 0x04;

    private const int NIIF_NOSOUND = 0x10;
    private const int NIIF_LARGE_ICON = 0x20;
    private const int NIIF_RESPECT_QUIET_TIME = 0x80;

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct NOTIFYICONDATA
    {
        public int cbSize /*= Marshal.SizeOf(typeof(NOTIFYICONDATA))*/;
        public IntPtr hWnd;
        public uint uID;
        public uint uFlags;
        public uint uCallbackMessage;
        public IntPtr hIcon;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x80)]
        public string szTip;
        public uint dwState;
        public uint dwStateMask;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x100)]
        public string szInfo;
        public uint uTimeoutOrVersion;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x40)]
        public string szInfoTitle;
        public uint dwInfoFlags;
        public Guid guidItem;
        public IntPtr hBalloonIcon;
    }

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
Find References
Show Printable Version
Revisions