我已实现静态嵌套分割窗口,求动态切换分割方式的方法。
我的例程是基于SDI的MFC程序,视图类基于CScrollView,共有4个视图类。
在MainFrm类中定义了2个分割窗口,用于进行嵌套分割。
CSplitterWnd m_wndSplitter;
// 新增加一个嵌套分割
CSplitterWnd m_wndSplitterSub;
在MainFrm类OnCreateClient中实现了静态嵌套分割。可以实现具有4个视图窗口的5中分割模式如下:
1 | 2
--|--
3 | 4
1 |
__|
2 | 4
--|
3 |
| 1
|__
4 | 2
|--
| 3
1 | 2 | 3
------------
4
4
------------
1 | 2 | 3
我目前只能是在更改分割方式后,存储分割方式,然后重新启动程序,
在MainFrm类OnCreateClient中根据存储的分割模式来实现了静态嵌套分割。
但是不知道如何实现动态切换分割方式,请高人指点。
分不够我可以增加。
期待高人指点,困扰了我很久。
------解决方案--------------------------------------------------------
网上有动态分割窗口的类,百度一下。
------解决方案--------------------------------------------------------
是动态切换view吗?
- C/C++ code
/////////////////////////////////////////////////////////// // Replace the current view in the splitter pSplitter // at pane (row, col) by a new view of class pViewClass void SwitchViewInSplitter( CSplitterWnd* pSplitter, int row, int col, CRuntimeClass* pViewClass ) { ASSERT_VALID( pSplitter ); ASSERT( pViewClass != NULL ); ASSERT( pViewClass-> IsDerivedFrom( RUNTIME_CLASS( CView ) ) ); // 1 - Find the view to be replaced CWnd* pPaneWnd = pSplitter->GetPane( row, col ); if( !pPaneWnd->IsKindOf( RUNTIME_CLASS( CView ) ) ) { TRACE2( "Unable to switch: pane (%d,%d) is not a view\n", row, col ); return; } CView* pCurrentView = static_cast<CView*>( pPaneWnd ); ASSERT_VALID( pCurrentView ); ASSERT_KINDOF( CView, pCurrentView ); if( pCurrentView->IsKindOf( pViewClass ) ) { // No need to switch for same view class return; } // 2 - Store current view position and activation state CRect rcView; pCurrentView->GetWindowRect( &rcView ); CView* pActiveView = pSplitter-> GetParentFrame()->GetActiveView(); BOOL bSaveActive = ( pActiveView == NULL ) || ( pActiveView == pCurrentView ); // 3 - Find the associated document CDocument* pDoc = pCurrentView->GetDocument(); ASSERT_VALID( pDoc ); // 4 - Make sure the document won't self-destruct // when current view is destroyed BOOL bSaveAutoDelete = pDoc->m_bAutoDelete; pDoc->m_bAutoDelete = FALSE; // 5 - Destroy the current view pCurrentView->DestroyWindow(); // 6 - Restore document to initial state pDoc->m_bAutoDelete = bSaveAutoDelete; // 7 - Initialize creation context used by CreateView() CCreateContext context; context.m_pNewDocTemplate = NULL; context.m_pLastView = NULL; context.m_pCurrentFrame = NULL; context.m_pNewViewClass = pViewClass; context.m_pCurrentDoc = pDoc; // 8 - Create the new view pSplitter->CreateView( row, col, pViewClass, rcView.Size(), &context ); CView* pNewView = static_cast<CView*> ( pSplitter->GetPane( row, col ) ); ASSERT_VALID( pNewView ); ASSERT_KINDOF( CView, pNewView ); // 9 - Position the new view like the old one and // activate it if needed pSplitter->ScreenToClient( &rcView ); pNewView->MoveWindow( &rcView, TRUE ); if( bSaveActive ) { pSplitter->GetParentFrame()->SetActiveView( pNewView ); } // 10 - Send WM_INITIALUPDATE to the view pNewView->GetParentFrame()->InitialUpdateFrame( pDoc, TRUE ); }