使用CSplitterWndEx将两个对话框(CDialog)添加到dockablepane(CDockablePane)

时间:2014-03-12 16:10:48

标签: mfc dialog split dockable-windows

在MFC应用程序中, 有一个可停靠的窗格,使用CSplitterWndEx分为2行。我尝试使用此拆分器添加两个对话框:

BOOL CPaneSplitter::AddWindow(int row, int col, CWnd* pWnd , CString clsName ,
DWORD dwStyle,DWORD dwStyleEx, SIZE sizeInit)
{

    // set the initial size for that pane
    m_pColInfo[col].nIdealSize = sizeInit.cx;
    m_pRowInfo[row].nIdealSize = sizeInit.cy;
    ASSERT(pWnd->m_hWnd == NULL);       // not yet created
    // Create with the right size (wrong position)
    CRect rect(CPoint(0,0), sizeInit);
    if (!pWnd->CreateEx(dwStyleEx,clsName,NULL,dwStyle,rect,this,IdFromRowCol(row,                    col)))
    { 
        return FALSE;
    } 
 }

修改

以下是创建拆分器的代码:

int CSplitePane::OnCreate(LPCREATESTRUCT lp)
{
    if(CDockablePane::OnCreate(lp)==-1)
        return -1;
    m_wndSplitter.CreateStatic(this,2,1);


    DWORD dwStyle = WS_CHILD | WS_VISIBLE ;
    if(!m_wndSplitter.AddWindow(0,0,&m_ChildDlg1,_T("My_Dailog_Pane"),dwStyle,0,CSize(100,100)))
        return -1;  
    m_ChildDlg1.ShowWindow(SW_SHOWDEFAULT);

    dwStyle = WS_CHILD | WS_VISIBLE | LVS_REPORT  | LVS_SHAREIMAGELISTS;
    if(!m_wndSplitter.AddWindow(1,0,&m_wndList,WC_LISTVIEW,dwStyle,0,CSize(100,100)))
        return -1; 

        m_wndList.ModifyStyle(LVS_TYPEMASK, LVS_ICON);

    return 0 ;
}
void CSplitePane::OnSize(UINT nType,int cx,int cy)
{
    CDockablePane::OnSize(nType,cx,cy);
    int cyTlb =0;// m_wndToolbar.CalcFixedLayout(FALSE, TRUE).cy;
    CRect rect;
    GetClientRect(rect);
    m_ChildDlg1.SetWindowPos(NULL,rect.left, rect.top, rect.Width(),rect.Height(),SWP_NOACTIVATE|SWP_NOZORDER);

    m_wndSplitter.SetWindowPos(NULL,rect.left
    , rect.top + cyTlb
    , rect.Width()  , rect.Height() - cyTlb , SWP_NOZORDER | SWP_NOACTIVATE);

}

此方法接受CWnd作为参数,但我传递了对话框本身,因此在运行应用程序时,窗格会被分割,但对话框控件不存在。

所以我的问题是: 是否可以使用CSplitterWndEx将CDialog对象添加到窗格?

2 个答案:

答案 0 :(得分:1)

使用CFormView派生类怎么样?

答案 1 :(得分:0)

也许您正在寻找的是CPaneDialog。查看VS 2008 Feature Pack示例中的SetPaneSize示例。摘自样本:

    void CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
            ...

        if (!m_wndDlgBar.Create (_T("DialogBar"), this, TRUE,
                         MAKEINTRESOURCE (IDD_DLG_BAR), 
                         WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI, 
                         ID_VIEW_DLGBAR))
        {
            TRACE0("Failed to create Dialog Bar\n");
            return FALSE;      // fail to create
        }

        m_wndDlgBar.EnableDocking(CBRS_ALIGN_ANY);
        m_wndDlgBar.DockToWindow (&m_wndWorkSpace, CBRS_ALIGN_BOTTOM);

        ...
    }

void CMainFrame::OnViewDialogBar() 
{
    ShowPane (&m_wndDlgBar, !(m_wndDlgBar.IsVisible ()), FALSE, TRUE);
    RecalcLayout ();
}

...