重新启动程序后,CDockablePane不会调整大小

时间:2013-12-17 18:27:20

标签: c++ mfc

我开始了一个单文档MFC项目,我创建了两个CDockablePane 我遇到的问题是,如果我移动或调整窗格并退出程序,当我重新启动程序时,它们的布局不会重置。他们的布局保持修改。

我猜我做错了或者Visual Studio生成了一些我找不到的代码。

我的CMainFrame::OnCreate功能:

// 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;   
}

我的面板初始化功能:

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 ;
}

OnCreate的{​​{1}}和OnSize函数:

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) ; } 的{​​{1}}和OnCreate函数:

OnSize

1 个答案:

答案 0 :(得分:1)

我认为停靠窗格默认记住它们的状态。看看herehere