Solved

Context Menu and Command Routing Mechanism

Posted on 1997-06-07
6
369 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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. …
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now