德尔福“托盘” 图标 (NotifyIcon) 上下文菜单在单击外部时不会消失

发布于 2024-07-27 22:31:37 字数 548 浏览 2 评论 0原文

我试图在右键单击我的通知图标时显示一个弹出菜单,效果很好; 但我希望当用户单击该菜单之外时菜单消失。

据推测,它是按照 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷弦 2024-08-03 22:31:37

我找到了解决办法!

我正在打电话
SetForegroundWindow(PopupMenu1.Handle);

这不起作用,但是在 OnPopup 事件处理程序中将其更改为

procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  // Hack to fix the "by design" behaviour of popups from notification area icons. 
  // See: http://support.microsoft.com/kb/135788
  BringToFront();
end;

有效!

显然,如果调用此函数时表单可见,您的应用程序将跳到最前面,但如果它是隐藏的(就像我的那样),那么它将起作用。

不过,我很想知道是否有一种方法可以使菜单正常工作,而无需窗口跳到最前面。

I've found a solution!

I was calling
SetForegroundWindow(PopupMenu1.Handle);

Which doesn't work, but changing this in the OnPopup event handler to

procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  // Hack to fix the "by design" behaviour of popups from notification area icons. 
  // See: http://support.microsoft.com/kb/135788
  BringToFront();
end;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文