0

假设我有一个有 2 行的拆分器。

--------
| |
--------
| |
--------

我如何做到这一点

---------
| | |
| | |
| | |
---------

从水平分割切换到垂直分割

无需重新创建整个拆分器?

代码是:

if (!m_wndSplitter.CreateStatic(this, 1, 2, WS_CHILD|WS_VISIBLE))
{
    TRACE0("Failed to create splitter window\n");
    return FALSE;
}
if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CWnd), CSize(200, 100), NULL))
{
    TRACE0("Failed to create CView1\n");
    return FALSE;
}
if (!m_wndSplitter.CreateView(0, 2, RUNTIME_CLASS(CWnd), CSize(500, 100), NULL))
{
    TRACE0("Failed to create CView2\n");
    return FALSE;
}
4

2 回答 2

0

不要用CreateStatic,只用Create在分离器上。然后你有一个所谓的动态分离器,在这里查看更多。

将拆分器从 horz 转换为 vert 时,您必须从拆分器中删除视图并在之后再次附加它们。您必须在文档类中执行此操作。如果需要,我可以发布一个方法来做到这一点。

好的,这是在窗格中切换视图的方法:

CView* CGMBefundDoc::SwitchToView(CView* pNewView,int row,int col)
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CSplitterWnd* pSplitter = &pMainWnd->m_wndSplitter;

CView* pOldActiveView = reinterpret_cast<CView*>(pSplitter->GetPane(row,col));
ASSERT(pOldActiveView != pNewView);

// 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(row,col));

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

我希望你明白这个想法,否则就问。

于 2010-12-28T10:03:17.277 回答
0

------------|----------| | | | | | | | |-----------| | | | | | | ------------|----------|

2 列拆分器,右侧有 2 行,一上一下,另一列左侧为上和下?

于 2011-01-22T09:43:39.620 回答