I have a NotifyIcon control that appears in the system tray. How can I find the location (x, y) of the icon on the screen?
Thanks
I have a NotifyIcon control that appears in the system tray. How can I find the location (x, y) of the icon on the screen?
Thanks
You can't. It isn't hard to get the window handle for the system tray, GetClassName() returns "ToolbarWindow32", the class name of the standard TOOLBAR common control. Beware that a 64-bit OS has two of them. Then you can send messages to it like TB_GETBUTTONINFO. Chief hang-ups are that you won't know what button ID to choose and the returned info does not include the button position.
Which is for the better, buttons move around without you being able to lock them.
Actually you can do this, here is code that shows you how and much more.
In any Mouse Event from NotifyIcon, simply look at Control.MousePosition, this contains the (x,y) of the mouse. The same can be done to position a ContextMenu on a form/control exactly where the form/control was clicked using these (x,y) values.
A good example of both of these is here:
More Here: http://code.msdn.microsoft.com/TheNotifyIconExample
After a long journey of trial and error, and the development of my own notify icon locator, I developed a way to find the best position icon, so far so good, until I saw this amazing project by @zhwang SuperNotifyIcon. This project has three ways to locate the notification icon, ranging from the inaccurate (like my own development) to the use of new in Windows 7 API. This is the definitive answer.
You can't. It isn't hard to get the window handle for the system tray, GetClassName() returns "ToolbarWindow32", the class name of the standard TOOLBAR common control. Beware that a 64-bit OS has two of them. Then you can send messages to it like TB_GETBUTTONINFO. Chief hang-ups are that you won't know what button ID to choose and the returned info does not include the button position.
Which is for the better, buttons move around without you being able to lock them.
© 2022 - 2024 — McMap. All rights reserved.