0

我创建了一个 MFC MDI 应用程序,并希望通过右键单击并选择“AddSplitWnd”弹出菜单项将窗口一次动态拆分为两部分。我尝试使用 CSplitterWnd::CreateStatic 来实现它,一旦窗口被拆分,它需要创建一个新视图,但我想使用以前的视图,所以有人知道如何实现它。谢谢你。

4

1 回答 1

0

这是在 SDI 环境中的拆分器中交换视图的代码片段。这也应该适用于 MDI。

CView* CDoc::SwitchToView(CView* pNewView)
{
    CFrameWndEx* pMainWnd = (CFrameWndEx*)AfxGetMainWnd();
    CView* pOldActiveView;
    pOldActiveView = pMainWnd->GetActiveView();
    CSplitterWnd* pSplitter = (CSplitterWnd *)pOldActiveView->GetParent();

    // in this case Pane 0,0 is exchanged
    pOldActiveView = (CView*) pSplitter->GetPane(0,0);

    // set flag so that document will not be deleted when view is destroyed
    m_bAutoDelete = FALSE;    
    // Dettach existing view
    RemoveView(pOldActiveView);
    // set flag back to default 
    m_bAutoDelete = TRUE;

    // Set the child window ID of the active view to the ID of the corresponding
    // pane. Set the child ID of the previously active view to some other ID.
    ::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, 0);
    ::SetWindowLong(pNewView->m_hWnd, GWL_ID, pSplitter->IdFromRowCol(0,0));

    // Show the newly active view and hide the inactive view.
    pNewView->ShowWindow(SW_SHOW);
    pOldActiveView->ShowWindow(SW_HIDE);

    // Attach new view
    AddView(pNewView);

    // Set active 
    pSplitter->GetParentFrame()->SetActiveView(pNewView);
    pSplitter->RecalcLayout(); 
    return pOldActiveView;
}

高温高压

于 2012-04-21T10:55:22.563 回答