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()前面,這樣就使得目前視窗變為前置了。
這樣當彈出菜單失去焦點之後,就會自動關閉了!其實這個所謂的設計,可害苦了程式員呀!!!