OnContextMenu() not working in view class
i have a popup menu for contextmenu.And i wrote the function for each menu in CMainframe. I have OnContextMenu() in each view class and in one dialog class.Its works fine in Dialog class.But not in View class.Codings are below: CMainframe funciton:
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);
}
Dialog class 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, poi开发者_C百科nt.y, this);
}
View class:
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);
}
When i press popup menu from Faceplate(Dialogclass),it goes to Mainframe function.At the same time when i press menu from any view class,it doesnot go to Mainframe function.Why its like that?
I'm not sure why it is working with your dialog class but I think the reason it is not working with your view class is because the last parameter for TracPopupMenu should be AfxGetMainWnd()
instead of this
.
精彩评论