Command routing beyond a split frame
The standard framework route does not include inactive views, which causes toolbar buttons and menus to gray when their mother view is deactivated. Users are confused. To bring back their happiness, I have overridden the CCmdTarget::OnCmdMsg function in the main frame (obviously derived from CFrameWnd):
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
CDocument *pDoc = GetActiveDocument();
if(pDoc)
{
POSITION pos = pDoc->GetFirstViewPosition();
CView *pView = NULL;
while(pView = pDoc->GetNextView(pos))
{
if(pView != GetActiveView()
&& pView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
}
}
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
I used a list of views contained in the active document (if any). The command message is passed to all views but the active one, which had a chance to handle it before it was routed to the frame window. If the message is handled by one of the views (OnCmdMsg indicates it by returning TRUE), no further processing is needed and we can return. Otherwise, the base class member is called to restore the conventional framework route.

Comments
Thanks
Posted by Legacy on 07/05/2003 12:00amOriginally posted by: Hans Wedemeyer
Great tip.... thanks.
Reply
Great
Posted by Legacy on 05/12/2003 12:00amOriginally posted by: Vilmos
Thanks. It is simple and works fine. Vilmos
ReplyUseful Technique !
Posted by Legacy on 04/29/2002 12:00amOriginally posted by: Mahesh Shimpi
Thanks a lot. That saved lot of my efforts in handling these mesg handlers in different splitter views.
ReplyThanks
Posted by Legacy on 01/06/2002 12:00amOriginally posted by: Vlad
This code gave me a free hour of guitar shredding
instead of looking into MFC manuals.
Reply
Conditional routing ("Ctrl" pressesd) - in view or document ???
Posted by Legacy on 12/14/2001 12:00amOriginally posted by: Amit Gefen
ReplyVery useful.
Posted by Legacy on 11/15/2001 12:00amOriginally posted by: Ritesh Kale
I would like to thank the author for this immensely useful contribution.
-Ritesh Kale
ReplyWow, I can keep my job.
Posted by Legacy on 10/17/2001 12:00amOriginally posted by: Dan
ReplyGracias
Posted by Legacy on 09/24/2001 12:00amOriginally posted by: Morgan
I owe you a cerveza for this one!
Reply
thanks for this hint
Posted by Legacy on 11/16/2000 12:00amOriginally posted by: Hemmi
After searching 2 weeks for a solution to handle menu commands in docking windows I found this article. And after 10 minutes my application works ....
thousend thanks to the author!
ReplyBrilliant
Posted by Legacy on 11/01/2000 12:00amOriginally posted by: Dennis
It's just easy code that does great things...
Reply
Loading, Please Wait ...