1

在 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 对象添加到窗格中?

4

2 回答 2

1

使用 CFormView 派生类怎么样?

于 2014-03-13T22:04:01.900 回答
0

也许您正在寻找的是CPaneDialog. 查看 VS 2008 Feature Pack Samples 中的 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 ();
}

...
于 2014-03-13T14:13:08.187 回答