我做了一个程序,现在遇到的一个难题是:我用鼠标右键点击一个目录,在出来的菜单中怎样加入一个选项,可以得到他的目录。

解决方案 »

  1.   

    响应消息WM_CONTEXTMENU
    然后添加代码
    if (point.x == -1 && point.y == -1)
    {
        CRect rect;
        GetClientRect(rect);
        ClientToScreen(rect);
        point = rect.TopLeft();
        point.Offset(5, 5);
    }
          
     CMenu menu;
     VERIFY(menu.LoadMenu(IDR_YOU_CONTEXT_MENU));//载入快捷菜单资源
     CMenu* pPopup = menu.GetSubMenu(0);
     ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this;//设置快捷菜单的主窗口 while (pWndPopupOwner->GetStyle() & WS_CHILD)
         pWndPopupOwner = pWndPopupOwner->GetParent();
     pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x,  point.y,pWndPopupOwner);