grbrand
asked on
Context menu handlers not being called
I have created a contect menu with message handlers in a modeless dialog which gets called from a DLL not the main app. Although the menu comes up on a right click the menu items for wich I have provided handlers are greyed out. All other messages are processed correctly. Normally this occurs when the windows messages do not make it to the dialog box. I don't know how to make sure they route to the dialog and where they are being eaten.
Does any one know how to stop this from happening or where to ensure the routing takes place?
BEGIN_MESSAGE_MAP(CEHRProp ertyPage1, CPropertyPage)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CEHRProper tyPage1)
ON_NOTIFY(NM_CLICK, IDC_TREE_DECISION_TREE, OnClickTreeDecisionTree)
ON_NOTIFY(NM_DBLCLK, IDC_TREE_DECISION_TREE, OnDblclkTreeDecisionTree)
ON_BN_CLICKED(IDC_BUTTON_E DIT_TREE, OnButtonEditTree)
ON_COMMAND(ID_POPUP_ADDSUB TREE, OnPopupAddSubTree)
ON_UPDATE_COMMAND_UI(ID_PO PUP_ADDSUB TREE, OnUpdatePopupAddsubtree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CEHRPropertyPage1::OnConte xtMenu(CWn d*, 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_ID R_POPUP_EH RPROPERTY_ PAGE1));
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);
}
}
void CEHRPropertyPage1::OnPopup AddSubTree ()
{
OnButtonEditTree();
}
void CEHRPropertyPage1::OnUpdat ePopupAdds ubtree(CCm dUI* pCmdUI)
{
pCmdUI->Enable();
}
Does any one know how to stop this from happening or where to ensure the routing takes place?
BEGIN_MESSAGE_MAP(CEHRProp
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CEHRProper
ON_NOTIFY(NM_CLICK, IDC_TREE_DECISION_TREE, OnClickTreeDecisionTree)
ON_NOTIFY(NM_DBLCLK, IDC_TREE_DECISION_TREE, OnDblclkTreeDecisionTree)
ON_BN_CLICKED(IDC_BUTTON_E
ON_COMMAND(ID_POPUP_ADDSUB
ON_UPDATE_COMMAND_UI(ID_PO
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CEHRPropertyPage1::OnConte
{
// 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_ID
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this;
while (pWndPopupOwner->GetStyle(
pWndPopupOwner = pWndPopupOwner->GetParent(
pPopup->TrackPopupMenu(TPM
pWndPopupOwner);
}
}
void CEHRPropertyPage1::OnPopup
{
OnButtonEditTree();
}
void CEHRPropertyPage1::OnUpdat
{
pCmdUI->Enable();
}
have you checked the menu ID defined in DLL, duplicated in the main application's resource.h?
Dialogs are rather fussy with menu's - they don't have some of the support for them built in the way a CFrameWnd base main frame has, in other words you have more to code yourself.
At this point
void CEHRPropertyPage1::OnConte xtMenu(CWn d*, CPoint point)
you are creating/loading the menu. After you load the menu you can then find the individual menu entries and enable them - so the OnUpdate... isn't necessary.
That I hope will solve your problem.
At this point
void CEHRPropertyPage1::OnConte
you are creating/loading the menu. After you load the menu you can then find the individual menu entries and enable them - so the OnUpdate... isn't necessary.
That I hope will solve your problem.
ASKER
How would you propose that I enable the individual menu entries? Can you give me an idea as to what the function calls would be?
ASKER
I have used EnableMenuItem but no change
UINT state = pPopup->EnableMenuItem( ID_EDIT_COPY, MF_ENABLED );
UINT state = pPopup->EnableMenuItem( ID_EDIT_COPY, MF_ENABLED );
ASKER
None of the above worked out.
The problem is solved by making the window that creates the context menu the parent.
The problem is solved by making the window that creates the context menu the parent.
ASKER
Last comment by me is the solution.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I had determined the solution from trial and error.