Shell_NotifyIcon (shell32)
Last changed: -80.169.130.50

.
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