假设我有一个包含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;
}
答案 0 :(得分:0)
请勿使用CreateStatic
,只需在分割器上使用Create
即可。然后你有一个所谓的动态分割器,请参阅更多here。
将分割器从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;
}
我希望你能得到这个想法,否则就问。
答案 1 :(得分:0)
----------- | ---------- | | | | | | | | | ---------- | | | | | | | ----------- | ---------- |
2列分离器,右侧有2行,一个向上,一个向下,另一个向左侧向上和向下?