Retrieves the Notifyicon bounding rectangle.
[DllImport("shell32.dll", SetLastError = true)]
static extern int Shell_NotifyIconGetRect([In]ref NOTIFYICONIDENTIFIER identifier, [Out]out RECT iconLocation);
NOTIFYICONIDENTIFIER
RECT
Do you know one? Please contribute it!
None.
Please add some!
[DllImport("shell32.dll", SetLastError = true)]
private static extern int Shell_NotifyIconGetRect([In]ref NOTIFYICONIDENTIFIER identifier, [Out]out RECT iconLocation);
[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;
}
public static RECT GetNotifyIconRect(IntPtr windowHandle, uint taskbarIconId)
{
var rect = new RECT();
var notifyCon = new NOTIFYICONIDENTIFIER();
notifyCon.cbSize = (uint) Marshal.SizeOf(notifyCon.GetType());
notifyCon.hWnd = windowHandle;
notifyCon.uID = taskbarIconId;
var shellNotifyIconGetRect = WinApi.Shell_NotifyIconGetRect(ref notifyCon, out rect);
if (shellNotifyIconGetRect == 0x80004005)
{
// E_FAIL, will happen if the icon is not there.
throw new Win32Exception(shellNotifyIconGetRect, "Failed to get icon position.");
}
if (shellNotifyIconGetRect != 0)
{
throw new Win32Exception(shellNotifyIconGetRect);
}
return rect;
}