Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Routing commands to the active docked window Collapse All
Subject Author Date
Daniel Vigovszky Jul 15, 2005 - 12:17 PM

Hello,

 

I have an MDI application with a text editor in the mdi child windows, and text editor in one of the docked windows as well. The standard command routing passes the clipboard commands (ID_EDIT_*) to the active MDI child window, but I would like to route it to the docked window when it has the focus.

 

I modified the frame window’s OnCmdMsg to route commands not handled by the document or view class to my docked windows, but for this clipboard thing the routing should be dynamic, always trying the active window (whether it is one of the mdi childs or a docking window).

 

I couldn’t find how to make it work. I’ve got problem with finding the active window. It seems that by default the MDI child windows and the docked windows are handled seperately - there is one active mdi child window and one active docking window at the same time.

 

So my question is how could I track the one "real" active window from the mdi childs and docking windows, or how else could I make clipboard work.

 

Thanks,

vigoo

Technical Support Jul 16, 2005 - 9:38 AM

To route editor commands correctly, your CMainFrame::OnCmdMsg() virtual method should look like:

BOOL CMainFrame::OnCmdMsg( ... )
{
    switch( nID )
    {
 
    case ID_EDIT_COPY:
    case ID_EDIT_CUT:
    case ID_EDIT_PASTE:
        {
            HWND hWndFocus = ::GetFocus();
            if( hWndFocus == NULL )
                break;
            CWnd * pWndFocusPermanent =
                CWnd::FromHandlePermanent( hWndFocus );
            if( pWndFocusPermanent == NULL )
                break;
            CEdit * pEdit =
                DYNAMIC_DOWNCAST(
                    CEdit, pWndFocusPermanent );
            if( pEdit == NULL )
                break;
            CWnd * pWndParentOfEdit =
                pEdit->GetParent();
            CExtControlBar * pBar =
 
                DYNAMIC_DOWNCAST(
                    CExtControlBar, pWndParentOfEdit );
            if( pBar == NULL )
                break;
            return pEdit->OnCmdMsg( ... );
        }
    }
    return __super::OnCmdMsg( ... );
}
This method will route all the standard editor commands specified in the switch statement to the focused editor window that is created inside the resizable control bar.

Daniel Vigovszky Jul 16, 2005 - 4:34 PM

Thank you for the code, it works well now. However, CMDIFrameWnd::OnCommand first sends the message to the mdi child window, and if it handles that, the OnCommand doesn’t call the OnCmdMsg. Because of this, the editor command did not reach the docked window, only the mdi child, while the update commands were routed correctly. For me, it was very strange and I had to debug a lot till I solved this. I have overwrite my frame window’s OnCommand, and call CFrameWnd::OnCommand instead of CMDIFrameWnd::OnCommand. With this addition, your code works well, and I hope that I won’t need the mdi frame’s functionality that sends the commands to the childs first.

Technical Support Jul 17, 2005 - 9:04 AM

We just want to add a comment on the design of your application. We think you need to create a stand alone toolbar for the editor window inside the resizable control bar. This toolbar should be placed at the top of the editor and contain commands relating to this editor only. You can find lots of windows with such design in the Visual Studio .NET. This design is more user friendly and let your users to avoid any misunderstanding.