Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Context menu handlers not being called

Posted on 2007-10-17
8
Medium Priority
?
1,163 Views
Last Modified: 2013-11-20
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();

}

0
Comment
Question by:grbrand
  • 5
  • 2
8 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 20098674
have you checked the menu ID defined in DLL, duplicated in the main application's resource.h?
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 20100185
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
 

Author Comment

by:grbrand
ID: 20103714
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:grbrand
ID: 20106733
I have used EnableMenuItem but no change
UINT state = pPopup->EnableMenuItem( ID_EDIT_COPY, MF_ENABLED );
0
 

Author Comment

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

Author Comment

by:grbrand
ID: 20519724
Last comment by me is the solution.
0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 1500 total points
ID: 20522157
>>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
 

Author Comment

by:grbrand
ID: 20578823
I had determined the solution from trial and error.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question