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 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:00am

    Originally posted by: Hans Wedemeyer

    Great tip.... thanks.

    Reply
  • Great

    Posted by Legacy on 05/12/2003 12:00am

    Originally posted by: Vilmos

    Thanks. It is simple and works fine. Vilmos

    Reply
  • Useful Technique !

    Posted by Legacy on 04/29/2002 12:00am

    Originally posted by: Mahesh Shimpi

    Thanks a lot. That saved lot of my efforts in handling these mesg handlers in different splitter views.

    Reply
  • Thanks

    Posted by Legacy on 01/06/2002 12:00am

    Originally 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:00am

    Originally posted by: Amit Gefen

    I made a conditional routing to one on my doc kinds. If the "Ctrl" button is pressed the command will be distributed to all document belongs to this template. If not only the active document will respond.
    
    Also it works fine, My difficulty is to accept that CDucument take care for "Ctrl" state that is part of GUI and belongs more to View and not Document. On the other hand it seems that it is the most suitable place.

    Someone have an opinion??? or suggestion???


    BOOL CLomahDoc::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
    {
    // TODO: Add your specialized code here and/or call the base class

    BOOL specified_command, bHandled = CDocument::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);

    //Specify to "Target" selecrion & "Reset"
    specified_command = ( ((nID>=ID_TARGET_F)&&(nID<=ID_TARGET_L))||
    ID_SESSION_RESET );

    if (bHandled && specified_command)
    {
    //AG__ (On "Ctrl" pressed: update also inactive similars)

    static BOOL in_process;

    if (!in_process)//eliminate infinite regresion
    if (::GetKeyState(VK_CONTROL)<0)//if "Ctrl" down
    {
    in_process = TRUE;//start

    POSITION DocPos = m_pDocTemplate->GetFirstDocPosition();

    while (DocPos)//iterate template members
    {
    CLomahDoc* pDoc =
    (CLomahDoc*) m_pDocTemplate->GetNextDoc(DocPos);

    if (pDoc!=this)//ignore self
    pDoc->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
    }

    in_process = FALSE;//end
    }

    //__AG
    }

    return bHandled;
    }

    Reply
  • Very useful.

    Posted by Legacy on 11/15/2001 12:00am

    Originally posted by: Ritesh Kale

    I would like to thank the author for this immensely useful contribution.

    -Ritesh Kale

    Reply
  • Wow, I can keep my job.

    Posted by Legacy on 10/17/2001 12:00am

    Originally posted by: Dan

    I had a feeling, in an abstract sense, that
    
    the problem was command routing. To come up
    with what you did would have taken me a
    long time. Thanks for your contribution.

    Reply
  • Gracias

    Posted by Legacy on 09/24/2001 12:00am

    Originally posted by: Morgan

    I owe you a cerveza for this one!

    Reply
  • thanks for this hint

    Posted by Legacy on 11/16/2000 12:00am

    Originally 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!

    Reply
  • Brilliant

    Posted by Legacy on 11/01/2000 12:00am

    Originally posted by: Dennis

    It's just easy code that does great things...

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

Most Popular Programming Stories

More for Developers

RSS Feeds