德尔福“托盘” 图标 (NotifyIcon) 上下文菜单在单击外部时不会消失
我试图在右键单击我的通知图标时显示一个弹出菜单,效果很好; 但我希望当用户单击该菜单之外时菜单消失。
据推测,它是按照 KB135788 - PRB:通知图标菜单无法正常工作 (存档)。
但据我所知,没有一个像样的应用程序有这样的行为。 我尝试致电 SetForegroundWindow< /strong> 使用弹出菜单的句柄无济于事。 我确信可以解决这个问题,就像我几年前做过的那样,但不记得如何解决。
有人知道如何实现预期的行为吗?
I'm trying to show a popup menu when right clicking my Notification Icon, which works fine; But I want the menu to disappear when the user clicks outside of that menu.
It's supposedly by design as per KB135788 - PRB: Menus for Notification Icons Do Not Work Correctly (archive).
But no decent app I know of behaves like this. I've tried calling SetForegroundWindow using the popup menu's handle to no avail. I'm sure it's possible to work around this, as I've done it years ago but don't remember how.
Anyone know how to achieve the expected behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决办法!
我正在打电话
SetForegroundWindow(PopupMenu1.Handle);
这不起作用,但是在 OnPopup 事件处理程序中将其更改为
有效!
显然,如果调用此函数时表单可见,您的应用程序将跳到最前面,但如果它是隐藏的(就像我的那样),那么它将起作用。
不过,我很想知道是否有一种方法可以使菜单正常工作,而无需窗口跳到最前面。
I've found a solution!
I was calling
SetForegroundWindow(PopupMenu1.Handle);
Which doesn't work, but changing this in the OnPopup event handler to
Works!
Obviously, if the form is visible when this is called, your app will jump foremost, but if it's hidden (as mine is), then it'll work.
I'd be interested to know if there's a way to make the menu work right without the window jumping foremost, though.