Mfc OnContextMenu()在视图类中不工作
我有一个contextmenu的弹出菜单。我在CMInframe中为每个菜单编写了函数。 我在每个视图类和一个对话框类中都有OnContextMenu()。它在对话框类中工作正常。但在视图类中没有。编码如下: CMInframe函数:Mfc OnContextMenu()在视图类中不工作,mfc,contextmenu,Mfc,Contextmenu,我有一个contextmenu的弹出菜单。我在CMInframe中为每个菜单编写了函数。 我在每个视图类和一个对话框类中都有OnContextMenu()。它在对话框类中工作正常。但在视图类中没有。编码如下: CMInframe函数: void CMainFrame::OnUpdateFptrend(CCmdUI* pCmdUI) { ((CMainFrame *)AfxGetMainWnd())->SendMessage(WM_COMMAND,ID_TRENDVIEW,NULL)
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);
}
对话框类上下文菜单:
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);
}
当我从面板(Dialogclass)中按下弹出菜单时,它将进入主机功能。同时,当我从任何视图类中按下菜单时,它没有进入大型机功能。为什么会这样?我不确定它为什么与dialog类一起工作,但我认为它不与view类一起工作的原因是,TracPopupMenu的最后一个参数应该是
AfxGetMainWnd()
,而不是this