gpt4 book ai didi

winapi - 当鼠标在焦点外单击时隐藏/关闭菜单

转载 作者:行者123 更新时间:2023-12-03 19:32:46 25 4
gpt4 key购买 nike

我有一个遗留代码,其中完成了 WIn 32 编程。

在这里,有一个托盘图标,右键单击时会启动一个菜单。

但是,即使在其焦点区域外单击菜单,该菜单仍然存在。

当我在其他地方单击鼠标时如何关闭菜单?

像 Qt 这样的框架可以很好地管理它。我是否必须跟踪鼠标指针,捕捉点击并查看它是否落在菜单区域之外?

代码是在遗留 C 中,并且没有使用面向对象的概念......所以我不能在这里覆盖某些东西。

请指教,谢谢。

最佳答案

阅读文档底部的备注 TrackPopupMenu功能:http://msdn.microsoft.com/en-us/library/windows/desktop/ms648002(v=vs.85).aspx

具体来说:

To display a context menu for a notification icon, the current window must be the foreground window before the application calls TrackPopupMenu or TrackPopupMenuEx. Otherwise, the menu will not disappear when the user clicks outside of the menu or the window that created the menu (if it is visible). If the current window is a child window, you must set the (top-level) parent window as the foreground window.

关于winapi - 当鼠标在焦点外单击时隐藏/关闭菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15494591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com