jliv902
jliv902

Reputation: 1658

CDockablePane does not resize after restarting the program

I started a Single Document MFC project and I have created two CDockablePanes.
The problem I'm having is that if I move or resize the panes and exit the program, their layout does not reset when I restart the program. Their layout stays modified.

I'm guessing I'm either doing something wrong or there is some code generated by Visual Studio that I'm not finding.

My CMainFrame::OnCreate function:

// Headers...

#define IDC_MYPANE_1 100
#define IDC_MYPANE_2 101

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    // A lot of pre-generated code...

    if (this->InitMyPane1 () == FALSE) {
        return -1 ;
    }

    if (this->InitMyPane2 () == FALSE) {
        return -1 ;
    }

    return 0;   
}

My panel initialization functions:

BOOL CMainFrame::InitMyPane1 ()
{
    DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_ALIGN_LEFT | CBRS_FLOAT_MULTI ;

    BOOL bOk = m_MyPane1.Create (
        _T ("MyPane 1"), this, 
        CRect (0, 0, 100, 300), TRUE, IDC_MYPANE_1, dwStyle
    ) ;

    if (bOk == FALSE) {
        return FALSE ;
    }

    m_MyPane1.EnableDocking (CBRS_ALIGN_ANY) ;
    this->DockPane ((CBasePane *) &m_MyPane1, AFX_IDW_DOCKBAR_LEFT) ;
    this->RecalcLayout () ;

    return bOk ;
}

BOOL CMainFrame::InitMyPane2 ()
{
    DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_ALIGN_LEFT | CBRS_FLOAT_MULTI ;

    BOOL bOk = m_MyPane2.Create (
        _T ("MyPane 2"), this, 
        CRect (0, 0, 200, 300), TRUE, IDC_MYPANE_2, dwStyle
    ) ;

    if (bOk == FALSE) {
        return FALSE ;
    }

    m_MyPane2.EnableDocking (CBRS_ALIGN_ANY) ;
    m_MyPane2.DockToWindow (&m_MyPane1, CBRS_ALIGN_RIGHT) ;

    this->RecalcLayout () ;

    return bOk ;
}

My OnCreate and OnSize functions for MyPane1:

int MyPane1::OnCreate (LPCREATESTRUCT lp)
{
    if (CDockablePane::OnCreate (lp) == -1) {
        return -1 ;
    }

    // Creates a CListCtrl for this pane (I have a member CListCtrl.)
    return this->CreateCListCtrl () ;
}

void MyPane1::OnSize (UINT nType, int cx, int cy)
{
    CDockablePane::OnSize (nType, cx, cy) ;

    CRect rect ;
    this->GetClientRect (&rect) ;

    m_MyList.SetWindowPos 
        (NULL, rect.left, rect.top, rect.Width (), rect.Height (), SWP_NOACTIVATE) ;

    m_MyList.SetColumnWidth (0, LVSCW_AUTOSIZE) ;
    m_MyList.SetColumnWidth (1, LVSCW_AUTOSIZE_USEHEADER) ;
}

My OnCreate and OnSize functions for MyPane2:

int MyPane2::OnCreate (LPCREATESTRUCT lp)
{
    if (CDockablePane::OnCreate (lp) == -1) {
        return -1 ;
    }

    // Creates a CListCtrl for this pane (I have a member CListCtrl.)
    return this->CreateCListCtrl () ;   
}

void MyPane2::OnSize (UINT nType, int cx, int cy)
{
    CDockablePane::OnSize (nType, cx, cy) ;

    CRect rect ;
    this->GetClientRect (&rect) ;

    m_MyList.SetWindowPos 
        (NULL, rect.left, rect.top, rect.Width (), rect.Height (), SWP_NOACTIVATE) ;

    m_MyList.SetColumnWidth (0, LVSCW_AUTOSIZE_USEHEADER) ;
    m_MyList.SetColumnWidth (1, LVSCW_AUTOSIZE_USEHEADER) ;
    m_MyList.SetColumnWidth (2, LVSCW_AUTOSIZE_USEHEADER) ;
    m_MyList.SetColumnWidth (3, LVSCW_AUTOSIZE_USEHEADER) ;
    m_MyList.SetColumnWidth (4, LVSCW_AUTOSIZE_USEHEADER) ;
    m_MyList.SetColumnWidth (5, LVSCW_AUTOSIZE_USEHEADER) ;
    m_MyList.SetColumnWidth (6, LVSCW_AUTOSIZE_USEHEADER) ;
    m_MyList.SetColumnWidth (7, LVSCW_AUTOSIZE_USEHEADER) ;
}

Upvotes: 1

Views: 1438

Answers (1)

rrirower
rrirower

Reputation: 4590

I think docking panes remember their state by default. Have look here and here

Upvotes: 1

Related Questions