Mangs
Mangs

Reputation: 1200

Set active panel in CSplitterWnd

I've created an mfc dialog with CSplitterWnd which has three different panels created like this:

BOOL CUserSplit::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
    WINDOWPLACEMENT wpDlg;
    GetWindowPlacement(&wpDlg);

    if (!m_wndSplitter.CreateStatic(this, 1, 3, WS_CHILD | WS_VISIBLE | WS_BORDER))
    {
        TRACE0("Failed to CreateStaticSplitter\n");
        return FALSE;
    }

    if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CSearchDlg), CSize(250, 0), pContext))
    {
        TRACE0("Failed to create first pane\n");
        return FALSE;
    }
    if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CProfileDlg), CSize(870, 0), pContext))
    {
        TRACE0("Failed to create second pane\n");
        return FALSE;
    }
    if (!m_wndSplitter.CreateView(0, 2, RUNTIME_CLASS(CControlDlg), CSize(0, 0), pContext))
    {
        TRACE0("Failed to create third pane\n");
        return FALSE;
    }
    SetWindowPos(NULL, 0, 0, 1285, 900, SWP_NOZORDER | SWP_NOMOVE);
    GetParentFrame()->CenterWindow();
    return TRUE;
}

When doing like this the first panel is active on load. How do I set the second (middle) panel to be active?

Upvotes: 0

Views: 295

Answers (2)

Andrew Komiagin
Andrew Komiagin

Reputation: 6556

You can get the view at specified location just like this:

CView* pView = (CView *)m_pWndSplitter->GetDlgItem(m_pWndSplitter->IdFromRowCol(0, 0));

After that just call

SetActiveView(pView); 

You can also try using the following method:

m_pWndSplitter->SetActivePane(nRow, nCol);

Upvotes: 3

Vlad Feinstein
Vlad Feinstein

Reputation: 11311

According to MSDN, you should call CSplitterWnd::SetActivePane()

Upvotes: 1

Related Questions