public static Rect? GetNotifyAreaButtonRectangle()
{
// find the handle of the taskbar
IntPtr taskbarparenthandle = NativeMethods.FindWindow("Shell_TrayWnd", null);
if (taskbarparenthandle == (IntPtr)null)
return null;
// find the handle of the notification area
IntPtr naparenthandle = NativeMethods.FindWindowEx(taskbarparenthandle, IntPtr.Zero, "TrayNotifyWnd", null);
if (naparenthandle == (IntPtr)null)
return null;
List<IntPtr> nabuttonwindows = NativeMethods.GetChildButtonWindows(naparenthandle);
if (nabuttonwindows.Count == 0)
return null; // found no buttons
IntPtr buttonpointer = nabuttonwindows[0]; // just take the first button
NativeMethods.RECT result;
if (!NativeMethods.GetWindowRect(buttonpointer, out result))
return null; // return null if we can't find the button
return result;
}