Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Win32 API to monitor, location, and orientation of Taskbar "Notification Area"?

The windows taskbar contains an area called the "Notification Area" or "system tray", where small icons appear for apps that want to run in the background and/or show system notifications. When the taskbar is on the bottom or the top of the screen, this area appears on the right.

In multi-monitor setups, this "Notification Area" only appears on one of the taskbars, even if the taskbar is set to show on all monitors. You can control which display the Notification Area appears on by dragging the taskbar to whichever display you prefer.

My question is:

Is there any straightforward API to find the screen, location, and orientation of the taskbar "Notification Area"?

I found one example which searches for the Shell_TrayWnd window handle, and then does math on its position try and figure out what orientation it is in (i.e. which edge of the screen the taskbar is on).

However, this is very fragile, as it depends on the current UI design of the windows taskbar.

Windows 10 introduced a new common toast notification system, including a snazzy notification flyout. However, even when you've moved the Notification Area to a different monitor, including the button which opens and closes the system notification flyout, the flyout itself is still displayed on the "primary monitor".

The above suggests there might be no way to do this, as if Microsoft's own notifications don't follow the Notification Area, there may be no way to practically do so. However, Microsoft documentation of the notification area suggests the very sensible idea that toast should display near it.... I think they just didn't think about the multi-monitor case.

microsoft toast location guideline

like image 368
David Jeske Avatar asked Dec 01 '17 08:12

David Jeske


1 Answers

If you want to show some window as a response to tray icon action there is no need to manually search for tray location because corresponding tray message will contain cursor coordinates as wparam. Even if event was generated by keyboard then message will contain icon upper left corner coordinates. See NOTIFYICONDATA structure documentation

like image 130
user7860670 Avatar answered Nov 10 '22 20:11

user7860670