我做的托盘右击弹出的菜单, 在失去焦点时并不自动隐藏(例如点击桌面, 切换到其它程序的窗口等)
, 要必须选择菜单上的一项才隐藏, 是怎么回事呢?
代码:CMenu menu, *pMenu;menu.LoadMenu( IDR_MENU1 );
pMenu = (CMenu *)menu.GetSubMenu( 0 );::SetMenuDefaultItem( pMenu->m_hMenu, 0, TRUE );pMenu->TrackPopupMenu( TPM_LEFTALIGN, lpoint->x, lpoint->y, this );// 资源回收
HMENU hmenu=menu.Detach();
menu.DestroyMenu();
delete lpoint;

解决方案 »

  1.   

    MSDN里的解释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). However, when the current window is the foreground window, the second time this menu is displayed, it displays and then immediately disappears. To correct this, you must force a task switch to the application that called
      

  2.   


    BringWindowToTop();pMenu->TrackPopupMenu( TPM_LEFTALIGN, lpoint->x, lpoint->y, this );就OK了
      

  3.   

    用了skin么?在Track完后向主窗口Post一条WM_NULL的消息看看。
      

  4.   

    用 SetForegroundWindow 将调用窗口置为前台窗口