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
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
shell_notifyicon (shell32)
 
.
Summary

Retrieves the Notifyicon bounding rectangle.

C# Signature:

    [DllImport("shell32.dll", SetLastError = true)]
    static extern int Shell_NotifyIconGetRect([In]ref NOTIFYICONIDENTIFIER identifier, [Out]out RECT iconLocation);

User-Defined Types:

NOTIFYICONIDENTIFIER

RECT

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Minimum supported client: Windows 7 [desktop apps only]

Minimum supported server: Windows Server 2008 R2 [desktop apps only]

Tips & Tricks:

Please add some!

Sample Code:

    [StructLayout(LayoutKind.Sequential)]
    public struct RECT
    {
        public Int32 left;
        public Int32 top;
        public Int32 right;
        public Int32 bottom;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct NOTIFYICONIDENTIFIER
    {
        public uint cbSize;
        public IntPtr hWnd;
        public uint uID;
        public Guid guidItem;
    }

    [DllImport("shell32.dll", SetLastError = true)]
    private static extern int Shell_NotifyIconGetRect([In]ref NOTIFYICONIDENTIFIER identifier, [Out]out RECT iconLocation);

    public static RECT GetNotifyIconRect(IntPtr windowHandle, uint taskbarIconId)
    {
        var rect = new RECT();
        var notifyIcon = new NOTIFYICONIDENTIFIER();
        notifyIcon.cbSize = (uint)Marshal.SizeOf(notifyIcon.GetType());
        notifyIcon.hWnd = windowHandle;
        notifyIcon.uID = taskbarIconId;
        var hresult = Shell_NotifyIconGetRect(ref notifyIcon, out rect);
        if (hresult == 0x80004005)
        {
            // E_FAIL, will happen if the icon is not there.
            throw new Win32Exception(hresult, "Failed to get icon position.");
        }

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

        return rect;
    }

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