Solved

Context Menu and Command Routing Mechanism

Posted on 1997-06-07
6
375 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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