我在resourse中建了一Menu2,是能响应消息的那种,现在我有;
void CMyView::OnRButtonDown(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
CMenu menu2; 
menu2.LoadMenu(IDR_MENU1); 
//CMenu *psubMenu=menu2.GetSubMenu(0);
//if(psubMenu==NULL){AfxMessageBox("haha");} POINT m_point;
LPPOINT m_lpoint;
m_lpoint = (LPPOINT)(&m_point); 
GetCursorPos(m_lpoint);
menu2.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,m_lpoint->x,m_lpoint->y,this); 
//menu2.DestroyMenu();
CView::OnLButtonDown(nFlags, point);
}
怎么在用这个GetSubMenu()函数时没有得到一个CMenu* 对象;
还有就是我单击右键时,弹出菜单太小了,看不清楚,如何调整?

解决方案 »

  1.   

    menu2.GetSubMenu(0)->TrackPopupMenu(TTPM_LEFTALIGN  ¦ TPM_RIGHTBUTTON,m_lpoint->x,m_lpoint->y,this);
    一般是在右键弹起的时候加载菜单吧
      

  2.   

    右键菜单可以更简单地做,VC6.0选择菜单Project/Add TO Project/Components and Controls...
    在目录c:\Program Files\Microsoft Visual Studio\Common\MSDev98\Gallery\Visual C++ Components下有个Pop-up Menu,插入到工程中就行,关闭后会有下面类似代码,编辑菜单CG_IDR_POPUP_DEVANG_VIEW,响应函数都可以了void CDevangView::OnContextMenu(CWnd*, CPoint point)
    { // CG: This block was added by the Pop-up Menu component
    {
    if (point.x == -1 && point.y == -1){
    //keystroke invocation
    CRect rect;
    GetClientRect(rect);
    ClientToScreen(rect); point = rect.TopLeft();
    point.Offset(5, 5);
    } CMenu menu;
    VERIFY(menu.LoadMenu(CG_IDR_POPUP_DEVANG_VIEW)); 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);
    }
    }
      

  3.   

    我也遇到过楼主这个问题,楼主可以试着在下面两个语句间添加:menu2.CreateMenu().或者是把CMenu menu2改为CMenu *menu2=new CMenu;CMenu menu2;  
    menu2.LoadMenu(IDR_MENU1);  
      

  4.   

    我也遇到过楼主这个问题,楼主可以试着在下面两个语句间添加:menu2.CreateMenu().或者是把CMenu menu2改为CMenu *menu2=new CMenu;CMenu menu2;  
    menu2.LoadMenu(IDR_MENU1);