How to find the location of the icon in the system tray

前端 未结 3 935
感情败类
感情败类 2020-12-20 23:28

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

相关标签:
3条回答
  • 2020-12-21 00:07

    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

    0 讨论(0)
  • 2020-12-21 00:08

    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.

    0 讨论(0)
  • 2020-12-21 00:09

    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.

    0 讨论(0)
提交回复
热议问题