Command routing beyond a split frame | CodeGuru

Command routing beyond a split frame

Abstract: The article present a simple method of routing WM_COMMAND messages through a number of views in a split frame window. This simplifies dealing with command routing and UI updates for inactive views. The standard framework route does not include inactive views, which causes toolbar buttons and menus to gray when their mother view is […]

Written By
CodeGuru Staff
CodeGuru Staff
Jul 27, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Abstract: The article present a simple method
of routing WM_COMMAND messages through a number of views in a split
frame window. This simplifies dealing with command routing and UI updates for
inactive views.

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.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.