SDK程序,不是VC/MFC.
改一个老程序,要求程序启动后在画面右下角的托盘上显示icon.点击icon出popup菜单。
现在功能总算都实现了。问题是用TrackPopupMenu函数弹出菜单后,如果鼠标离开菜单(比如说单击桌面)的话,菜单并不消失。我发现是TrackPopupMenu函数还没有返回。怎么办?
查了一下旧帖,只有VC/MFC里的TrackPopupMenu问题,好像不大一样。

解决方案 »

  1.   

    在trackpopupmenu前加上SetForegroundWindow(hDlg);
    hDlg就是trackpopupmenu里指定的那个父窗口句柄
    分数全给我
      

  2.   

    TrackPopupMenu
    你是怎么调用的啊
      

  3.   

    PRB: Menus for Notification Icons Do Not Work Correctly
    适用于
    This article was previously published under Q135788 
    SYMPTOMS
    When you display a context menu for a notification icon (see Shell_NotifyIcon), clicking anywhere besides the menu or the window that created the menu (if it is visible) doesn't cause the menu to disappear. When this behavior is corrected, the second time this menu is displayed, it displays and then immediately disappears. RESOLUTION
    To correct the first behavior, you need to make the current window the foreground window before calling TrackPopupMenu or TrackPopupMenuEx. The second problem is caused by a problem with TrackPopupMenu. It is necessary to force a task switch to the application that called TrackPopupMenu at some time in the near future. This can be accomplished by posting a benign message to the window or thread. The following code will take care of all of this:    SetForegroundWindow(hDlg);   // Display the menu
       TrackPopupMenu(   hSubMenu,
                         TPM_RIGHTBUTTON,
                         pt.x,
                         pt.y,
                         0,
                         hDlg,
                         NULL);   PostMessage(hDlg, WM_NULL, 0, 0);

    STATUS
    This behavior is by design.