Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Context Menu and Command Routing Mechanism

Posted on 1997-06-07
6
Medium Priority
?
389 Views
Last Modified: 2013-11-20
I am using  VC 5.0.
In my MDI application  I added a context menu (TrackPopupMenu) to  the CTreeCtrl class inserted into CControlBar. The handlers of the menu commands are implemented in the CMainFrame class. When the bar is docked everything is OK: commands are
handled successfully. BUT when I undock the bar all items in the context  menu become gray. As I understand MFC stop "seeing" the handlers in  CMainFrame.
I guess that something is wrong with the command routing mechanism, but I can't catch what exactly fails.
0
Comment
Question by:Dimach
  • 3
  • 3
6 Comments
 
LVL 1

Expert Comment

by:mrosen
ID: 1302003
Try adding UPDATE_COMMAND_UI messages for each of the menu items in classwizard. This gives you code like this:

In the message map:
ON_UPDATE_COMMAND_UI(ID_REFRESH, OnUpdateRefresh)

void CMainFrame::OnUpdateRefresh(CCmdUI* pCmdUI)
{
     //Just call Enable unless there is some reason not to (from your app)
     pCmdUI->Enable(TRUE);
}
0
 

Author Comment

by:Dimach
ID: 1302004
Even if I artificially enable items, handlers won't be executed when the bar is undocked!

0
 
LVL 1

Accepted Solution

by:
mrosen earned 150 total points
ID: 1302005
Ok. I just found out my app has this bug. I haven't tried it out yet, but I'm going to derive my own CToolbar and implement the menu command IDs there.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Dimach
ID: 1302006
Thank you for reply.
Take into account that I have a few tree controls in the bar and I wish each tree has a separate context menu. That is quite similar to the Project workspace window in VC (MFC newsgroups full of questions how to implement features similar to ones Developer Studio has, but I didn’t see anything looking like this). Are you sure that implementation of the menu command IDs in the bar is a good idea?

0
 
LVL 1

Expert Comment

by:mrosen
ID: 1302007
To be honest, I'm not sure there. One very unelegant aspect of MFC is the fact that controls in toolbars or dialog bars are processed through the CMainFrame class, not the view class. You should derive each of the tree controls and handle the OnLButtonDown message, calling a TrackPopupMenu at the point given by OnLButtonDown.
0
 

Author Comment

by:Dimach
ID: 1302008
I've solved  the problem.
To call the context menu I used the following code (used in MFC examples attached to VC):

CWnd* pWndPopupOwner = this;
// The following cycle returns different  CWnd for docked/undocked
// control bar:
//    CMainFrame         - for the docked bar
//    CMiniFrameWnd - for the undocked bar
while( pWndPopupOwner->GetStyle() & WS_CHILD )
       pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
                     point.x, point.y, pWndPopupOwner);

As a result CMaintFrame handlers are not called for the undocked control bar. To fix  the bug it's necessary to write:
pWndPopupOwner = AfxGetMainWnd();

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

916 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