如何找到系统托盘中图标的位置
我有一个出现在系统托盘中的 NotifyIcon 控件。 如何找到图标在屏幕上的位置(x,y)?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上你可以做到这一点,这里的代码向你展示了如何做到以及更多。
在来自 NotifyIcon 的任何鼠标事件中,只需查看 Control.MousePosition,其中包含鼠标的 (x,y)。 可以使用这些 (x,y) 值将 ContextMenu 准确地定位在窗体/控件上单击窗体/控件的位置。
这两个的一个很好的例子在这里:
更多这里:http://code.msdn.microsoft.com/ NotifyIcon示例
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
经过漫长的尝试和错误,以及我自己的通知图标定位器的开发,我开发了一种找到最佳位置图标的方法,到目前为止一切都很好,直到我看到了 @zhwang SuperNotifyIcon。 这个项目有三种方式来定位通知图标,从不准确(像我自己开发的)到使用Windows 7中新的API。 这是最终的答案。
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.
你不能。 获取系统托盘的窗口句柄并不难,GetClassName() 返回“ToolbarWindow32”,即标准 TOOLBAR 公共控件的类名。 请注意,64 位操作系统有两个。 然后你可以向它发送消息,如 TB_GETBUTTONINFO。 主要的问题是您不知道要选择哪个按钮 ID,并且返回的信息不包括按钮位置。
更好的是,按钮可以四处移动,而您无法锁定它们。
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.