Solved

Context Menu and Command Routing Mechanism

Posted on 1997-06-07
6
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Suggested Courses

752 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