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(CEHRPropertyPage1, CPropertyPage)
      ON_WM_CONTEXTMENU()
      //{{AFX_MSG_MAP(CEHRPropertyPage1)
      ON_NOTIFY(NM_CLICK, IDC_TREE_DECISION_TREE, OnClickTreeDecisionTree)
      ON_NOTIFY(NM_DBLCLK, IDC_TREE_DECISION_TREE, OnDblclkTreeDecisionTree)
      ON_BN_CLICKED(IDC_BUTTON_EDIT_TREE, OnButtonEditTree)
      ON_COMMAND(ID_POPUP_ADDSUBTREE, OnPopupAddSubTree)
      ON_UPDATE_COMMAND_UI(ID_POPUP_ADDSUBTREE, OnUpdatePopupAddsubtree)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CEHRPropertyPage1::OnContextMenu(CWnd*, 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_IDR_POPUP_EHRPROPERTY_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::OnPopupAddSubTree()
{
      OnButtonEditTree();
}

void CEHRPropertyPage1::OnUpdatePopupAddsubtree(CCmdUI* pCmdUI)
{
       pCmdUI->Enable();

}

grbrandAsked:
Who is Participating?
 
AndyAinscowFreelance programmer / ConsultantCommented:
>>The problem is solved by making the window that creates the context menu the parent.


From your original code
           CWnd* pWndPopupOwner = this;

            while (pWndPopupOwner->GetStyle() & WS_CHILD)
                  pWndPopupOwner = pWndPopupOwner->GetParent();

            pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
                  pWndPopupOwner);


Which actually sets the owner of the menu to the parent of your property page, that sheet should pass the messages onto the child windows (property pages) for handling.  
0
 
Roshan DavisCommented:
have you checked the menu ID defined in DLL, duplicated in the main application's resource.h?
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
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::OnContextMenu(CWnd*, 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.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
grbrandAuthor Commented:
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?
0
 
grbrandAuthor Commented:
I have used EnableMenuItem but no change
UINT state = pPopup->EnableMenuItem( ID_EDIT_COPY, MF_ENABLED );
0
 
grbrandAuthor Commented:
None of the above worked out.
The problem is solved by making the window that creates the context menu the parent.
0
 
grbrandAuthor Commented:
Last comment by me is the solution.
0
 
grbrandAuthor Commented:
I had determined the solution from trial and error.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.