MFC 托盘弹出控制菜单后,单击其他地方或按ESC键也都不能使托盘菜单消失(一直悬挂着怪让人难受的),必须选择托盘菜单里的控制选项才能关闭菜单(好比到一家餐厅不点菜不给走呀),这是个很严重的问题,因为如果你的菜单里面只有“关闭”按钮,那是程序的灾难了…
不过MSDN中给出了解决办法:
135788:Menus for Notification Icons Do Not Work Correctly
SYMPTOMS:When you display a context menu for a notification icon, clicking anywhere besides the menu or the window that created the menu doesn’t cause the menu to disappear.
RESOLUTION:To correct the first behavior, you need to make the current window the foreground window before calling TrackPopupMenu or TrackPopupMenuEx.
修正办法就是将SetForegroundWindow()放在pSubMenu->TrackPopupMenu()前面,这样就使得当前窗口变为前置了。
这样当弹出菜单失去焦点之后,就会自动关闭了!
来自:
http://blog.csdn.net/nonecode/article/details/7950840
大致就是这样吧…
【MFC】托盘菜单失去焦点自动关闭