Search code examples
mfcfocuschildviewscsplitterwnd

How to focus on a certain view in a MFC CSplitter


I'm trying to create an hierarchic window that contains 3 views using CMDIChildWnd, 2 CSplitterWnd's and 3 CFormView's:

  1. A form view that contains a static control
  2. A form to display the main window that I use to view a PDF document
  3. A side panel for some actions related to the main view

The main splitter (containing the MainView and TaskPane) is initialized with 1 row and 2 columns. The second splitter contains 2 rows and 1 column, containing the Tabs and the main splitter.

This image describes how it should be built: Visual description

My problem is that the MainView has no focus and therefore, the tool bar buttons are not enabled for zooming, saving as, etc...

When I'm not using the Banner Splitter, it works fine. I tried the setActivePane() setFocus() setActiveWindow() Here is how I create it in the CChildFrame::OnCreateClient()

if (m_BannerSplitter->CreateStatic(this, 2, 1))
{
    m_BannerSplitter->CreateView(0,
                                0,
                                RUNTIME_CLASS(CBannerView),
                                CSize(r.Width(),28),
                                pContext);
    m_splitter->CreateStatic(m_BannerSplitter,
                                1,
                                2,
                                WS_CHILD | WS_VISIBLE | WM_SHOWWINDOW, 
                                m_BannerSplitter->IdFromRowCol(1,0));

}
else
{
    m_splitter->CreateStatic(this, 1, 2);
}

m_splitter->CreateView(0,
                        0,
                        RUNTIME_CLASS(CMainView), 
                        CSize(r.Width()-m_splitter->m_iRightTabFullWidth-14,1),
                        pContext);
m_splitter->CreateView(0,
                        1,
                        RUNTIME_CLASS(CTasksView),
                        CSize(m_splitter->m_iRightTabFullWidth, 1),
                        pContext);

m_splitter->SetColumnInfo(1,
                            m_splitter->m_iRightTabFullWidth, 
                            m_splitter->m_iRightTabFullWidth);

Solution

  • I have found the solution and it was pretty simply. The object contains the splitters is a CMDIChildWnd that has SetActiveView(CView * view) function.

    So I tried to get the view using:

    CView *mainView = (CView *)m_splitter->GetDlgItem(m_splitter->IdFromRowCol(0, 0)); 
    

    and than used from the CChildFrame::OnCreateClient() event

    SetActiveView(mainView);