Delphi “Tray” icon (NotifyIcon) context-menu does not disappear when clicking outside it

微笑、不失礼 提交于 2019-12-02 11:05:53

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!