Locating the tray icon

My application is designed to be placed in the system tray and behaves similarly to the elements of the "Network / Volume / Power / Action Center" tray in Windows 7 (and the equivalent elements in Windows Vista). That is, it becomes visible when you click on the tray icon and becomes hidden when the focus is lost.

The application is written in WPF, but currently I'm using NotifyIcon from WinForms for the tray icon.

I would like to know if anyone has any suggestions regarding how I can determine the position (e.g. screen coordinates) of my application icon. Windows Vista / 7 tray items have a default way to do this, since the pop-ups are centered over the corresponding tray icon.

In Vista, this was not a big problem: I had an application permanently installed in the lower right corner, and it looked great (although there was no logic enabled for cases where the taskbar was not placed at the bottom of the screen). However, in Windows 7, my application closes the pop-up window of the new system tray, instead of hovering over it, for example, using volume controls, etc.

The best solution I've seen in my searches is to handle the mouse-up event on NotifyIcon and use the mouse coordinates to determine the position of the icon. I think that in the end I use this method if someone does not have a better idea, although it is not ideal, because the position will be slightly different depending on where inside the icon that the user clicks.

+6
wpf position coordinates system-tray notifyicon
source share
2 answers

Windows 7 and above expose the Shell_NotifyIconGetRect () function, which returns the screen coordinates of the rectangle bounding the icon.

You will need to provide it with a notification identifier identifier, but I do not know if you can access this property through a managed NotifyIcon .

+6
source share

In addition to this, I wrote about a method for finding the location of the notification icon when the Shell_NotifyIconGetRect function is not available: http://blog.quppa.net/2010/12/28/windows-7-style-notification-area-applications-in-wpf -part-6-notify-icon-position-pre-windows-7 /

+4
source share

All Articles