Link to home
Start Free TrialLog in
Avatar of grbrand
grbrandFlag for Canada

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(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();

}

Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

have you checked the menu ID defined in DLL, duplicated in the main application's resource.h?
Avatar of AndyAinscow
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.
Avatar of grbrand

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?
Avatar of grbrand

ASKER

I have used EnableMenuItem but no change
UINT state = pPopup->EnableMenuItem( ID_EDIT_COPY, MF_ENABLED );
Avatar of grbrand

ASKER

None of the above worked out.
The problem is solved by making the window that creates the context menu the parent.
Avatar of grbrand

ASKER

Last comment by me is the solution.
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of grbrand

ASKER

I had determined the solution from trial and error.