Reputation: 53
I'm having a problem with the RMB Context menus, In my main frame I have a grid control with the RMB context menu event. The shortcut keys appear correctly. See Copy for Ctrl + C,Paste for Ctrl + V, etc...
Then I have a dialog with already a bunch of codes from other dev's. And this dialog somehow makes the RMB Context menu funky. The shortcut keys no longer appear. It may be caused by altering the PreTransalateMessage and some messages are not going through right or maybe some shell functions that may had a conflict. Because when you notice the window it's still using the windows aero basic theme while I'm using Windows 10 because of the pin icon beside the minimize.
This is the code used in the mainframe as well as in the dialog.
void MyDialog::OnContextMenu(CWnd* pWnd, CPoint ptMousePos)
{
CMenu *menuRightClick;
menuRightClick->LoadMenu(IDR_RIGHTCLICK);
CMenu *pPopupVitmMenu;
pPopupVitmMenu = menuRightClick->GetSubMenu(9);
ASSERT(pPopupVitmMenu);
if (pPopupVitmMenu)
{
CPoint point;
::GetCursorPos(&point);
CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
CMFCPopupMenu* pPopup = CMFCPopupMenu::GetActiveMenu();
//close already poped up menus, if any.
if (pPopup != NULL)
pPopup->CloseMenu();
pPopupMenu->Create(this, point.x, point.y, pPopupVitmMenu->Detach(), FALSE, TRUE);
pPopupMenu->ShowWindow(SW_SHOW);
}
}
This maybe related or unrelated but the old context menu doesn't get dimissed when you RMB on another area. It only disappears when you click outside the application(Desktop,Taskbar).
I know the information is vague, but that's all I can provide. Thanks in advance!
Upvotes: 3
Views: 1611
Reputation: 1
Ensure that your MyDialog is either of type CDialogEx or CMFCPropertyPage.
Within the CMFCPopupMenu::Create function, the CMFCPopupMenu::NotifyParentDlg function will be invoked.
BOOL CMFCPopupMenu::NotifyParentDlg(BOOL bActivate)
{
CDialogEx* pDlg = DYNAMIC_DOWNCAST(CDialogEx, m_pMessageWnd);
CMFCPropertyPage* pPropPage = DYNAMIC_DOWNCAST(CMFCPropertyPage, m_pMessageWnd);
if (pDlg == NULL && pPropPage == NULL)
{
return FALSE;
}
if (!bActivate && m_pActivePopupMenu != this)
{
return FALSE;
}
if (pDlg != NULL)
{
pDlg->SetActiveMenu(bActivate ? this : NULL);
}
if (pPropPage != NULL)
{
pPropPage->SetActiveMenu(bActivate ? this : NULL);
}
return TRUE;
}
The deletion of the popup menu is contingent upon whether the parent or message window has set the active menu.
Upvotes: 0
Reputation: 31599
Use theApp.GetContextMenuManager()
to get access to CContextMenuManager
. Where theApp
is the main CWinApp
class. It should be calling InitContextMenuManager()
during initialization.
CMenu menu;
menu.LoadMenu(IDR_MAINFRAME);
CMenu *popup = menu.GetSubMenu(0);
if(popup)
{
CContextMenuManager *manager = theApp.GetContextMenuManager();
if(manager)
//for CDialogEx:
manager->ShowPopupMenu(popup->Detach(), p.x, p.y, this, TRUE, TRUE, FALSE);
//for CDialog:
//manager->ShowPopupMenu(popup->Detach(), p.x, p.y, this, FALSE, TRUE, FALSE);
}
Note that the 5th parameter should be TRUE
for CDialogEx
, and FALSE
for CDialog
Upvotes: 1