是你的TrackPopupMenu函数的uFlags设置不当,TPM_LEFTALIGN|TPM_LEFTBUTTON

解决方案 »

  1.   

    用Shell_NotifyIcon由两个问题:
    1.就像你说的菜单不消失
    2.菜单显示时,你在去按右键又会弹出第二个菜单
    解决方法 在MSDN中 QID=136788中已给出。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); 
      

  2.   

    TPM_LEFTALIGN | TPM_LEFTBUTTON |TPM_RIGHTBUTTON | TPM_RETURNCMD
      

  3.   

    longx真正解决了我的问题,所以我把20分献上
      

  4.   

    如果用的API函数,则在弹出菜单后面添加PostMessage(hDlg, WM_NULL, 0, 0); 
    如果使用CMenu及其派生类,则添加menu.DestroyMenu();
      

  5.   

        wbqbook你是如何响应右键弹出菜单的,任务栏中间的窗口还有可见吗?