我有一个上下文菜单的弹出菜单。我为CMainframe中的每个菜单编写了函数。 我在每个视图类和一个对话框类中都有OnContextMenu()。它在Dialog类中工作正常。但不在View类中。编码如下: CMainframe功能:
void CMainFrame::OnUpdateFptrend(CCmdUI* pCmdUI)
{
((CMainFrame *)AfxGetMainWnd())->SendMessage(WM_COMMAND,ID_TRENDVIEW,NULL);
}
void CMainFrame::OnUpdateFptuning(CCmdUI* pCmdUI)
{
((CMainFrame *)AfxGetMainWnd())->SendMessageWM_COMMAND,ID_TUNINGVIEW,NULL);
}
对话框类Contextmenu:
void CFacePlate::OnContextMenu(CWnd* pWnd, CPoint point)
{
CMenu mnuPopup;
mnuPopup.LoadMenu(IDR_FPMENU);
CRect rBarRect;
rBarRect.left = rBarRect.top = 0;
rBarRect.right = 1000;rBarRect.bottom = 300;
CMenu *mnuPopupMenu = mnuPopup.GetSubMenu(0);
ASSERT(mnuPopupMenu);
if( rBarRect.PtInRect(point) )
mnuPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
}
查看课程:
void CGroupView::OnContextMenu(CWnd* pWnd, CPoint point)
{
CMenu mnuPopup;
mnuPopup.LoadMenu(IDR_FPMENU);
CRect rBarRect;
rBarRect.left = rBarRect.top = 0;
rBarRect.right = 1150;rBarRect.bottom = 390;
CMenu *mnuPopupMenu = mnuPopup.GetSubMenu(0);
ASSERT(mnuPopupMenu);
if( rBarRect.PtInRect(point) )
mnuPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
}
当我从Faceplate(Dialogclass)按下弹出菜单时,它会转到Mainframe功能。同时当我从任何一个视图类按下菜单时,它不会转到Mainframe功能。为什么会这样?
答案 0 :(得分:1)
我不确定为什么它与您的对话框类一起使用但我认为它不适用于您的视图类的原因是因为TracPopupMenu的最后一个参数应该是AfxGetMainWnd()
而不是this