2013-07-21
展开全部
《这是我在网上摘的,不知道对你有用吗》 void EkSwitchViewInSplitter(CMySplitterWnd *pSplitter, int row, int col, CRuntimeClass *pViewClass)
{
ASSERT_VALID( pSplitter );
ASSERT( pViewClass != NULL );
ASSERT( pViewClass->IsDerivedFrom( RUNTIME_CLASS( CView ) ) );
//查找要替换的视图
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 (pPaneWnd);
ASSERT_VALID( pCurrentView );
ASSERT_KINDOF( CView,pCurrentView );
if(pCurrentView->IsKindOf(pViewClass))
{
return;
}
//保存当前视图的位置和活动状态
CRect rcView;
pCurrentView->GetWindowRect( &rcView );
CView* pActiveView = pSplitter->GetParentFrame()->GetActiveView();
BOOL bSaveActive = ( pActiveView == NULL ) || (pActiveView == pCurrentView );
//查找相关的文档
CDocument* pDoc = pCurrentView->GetDocument();
ASSERT_VALID( pDoc);
//当释放活动窗口时,确保文档不会自我析构
BOOL bSaveAutoDelete = pDoc->m_bAutoDelete;
pDoc->m_bAutoDelete = FALSE;
//释放活动视图
pCurrentView->DestroyWindow();
//恢复文档到初始状态
pDoc->m_bAutoDelete = bSaveAutoDelete;
//初始化CreatView()使用的创建上下文
CCreateContext context;
context.m_pNewDocTemplate = NULL;
context.m_pLastView = NULL;
context.m_pCurrentFrame = NULL;
context.m_pNewViewClass = pViewClass;
context.m_pCurrentDoc = pDoc;
//创建新的视图
pSplitter->CreateView( row,col,pViewClass,rcView.Size(),&context );
CView* pNewView = static_cast(pSplitter->GetPane( row,col ));
ASSERT_VALID( pNewView );
ASSERT_KINDOF( CView, pNewView );
//定位新视图,与旧视图位置相同,如果需要则激活它
pSplitter->ScreenToClient( &rcView );
pNewView->MoveWindow( &rcView, TRUE );
if( bSaveActive )
{
pSplitter->GetParentFrame()->SetActiveView( pNewView );
}
//给视图发送WM_INITIALUPDATE
pNewView->GetParentFrame()->InitialUpdateFrame( pDoc,TRUE );
}
{
ASSERT_VALID( pSplitter );
ASSERT( pViewClass != NULL );
ASSERT( pViewClass->IsDerivedFrom( RUNTIME_CLASS( CView ) ) );
//查找要替换的视图
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 (pPaneWnd);
ASSERT_VALID( pCurrentView );
ASSERT_KINDOF( CView,pCurrentView );
if(pCurrentView->IsKindOf(pViewClass))
{
return;
}
//保存当前视图的位置和活动状态
CRect rcView;
pCurrentView->GetWindowRect( &rcView );
CView* pActiveView = pSplitter->GetParentFrame()->GetActiveView();
BOOL bSaveActive = ( pActiveView == NULL ) || (pActiveView == pCurrentView );
//查找相关的文档
CDocument* pDoc = pCurrentView->GetDocument();
ASSERT_VALID( pDoc);
//当释放活动窗口时,确保文档不会自我析构
BOOL bSaveAutoDelete = pDoc->m_bAutoDelete;
pDoc->m_bAutoDelete = FALSE;
//释放活动视图
pCurrentView->DestroyWindow();
//恢复文档到初始状态
pDoc->m_bAutoDelete = bSaveAutoDelete;
//初始化CreatView()使用的创建上下文
CCreateContext context;
context.m_pNewDocTemplate = NULL;
context.m_pLastView = NULL;
context.m_pCurrentFrame = NULL;
context.m_pNewViewClass = pViewClass;
context.m_pCurrentDoc = pDoc;
//创建新的视图
pSplitter->CreateView( row,col,pViewClass,rcView.Size(),&context );
CView* pNewView = static_cast(pSplitter->GetPane( row,col ));
ASSERT_VALID( pNewView );
ASSERT_KINDOF( CView, pNewView );
//定位新视图,与旧视图位置相同,如果需要则激活它
pSplitter->ScreenToClient( &rcView );
pNewView->MoveWindow( &rcView, TRUE );
if( bSaveActive )
{
pSplitter->GetParentFrame()->SetActiveView( pNewView );
}
//给视图发送WM_INITIALUPDATE
pNewView->GetParentFrame()->InitialUpdateFrame( pDoc,TRUE );
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-21
展开全部
BOOL CChildFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
// 产生静态分裂视窗,将参数一的句柄视图窗口分为横列为 1,纵行为 2。
m_wndSplitter1.CreateStatic(this, 1, 2);
// 产生分裂视窗的第一个窗口(标号 0,0)的 view 视窗,采用 CTextView。
m_wndSplitter1.CreateView(0, 0, RUNTIME_CLASS(CTextView),CSize(300, 0), pContext); // 产生第二个分裂视窗,横列为2 纵行为1。位在第一个分裂视窗的(0,1)窗口
m_wndSplitter2.CreateStatic(&m_wndSplitter1, 2, 1,WS_CHILD | WS_VISIBLE, m_wndSplitter1.IdFromRowCol(0, 1));
// 产生第二个分裂视窗的第一个窗口(标号 0,0)的 view 视窗,采用 CBarView。
m_wndSplitter2.CreateView(0, 0, RUNTIME_CLASS(CBarView),CSize(0, 150), pContext);
// 产生第二个分裂视窗的第二个窗口(标号 1,0)的 view 视窗,采用 CGraphView。
m_wndSplitter2.CreateView(1, 0, RUNTIME_CLASS(CGraphView),CSize(0, 0), pContext);//CSize(0, 0)就是剩余的空间大小 // 设定 active pane
SetActiveView((CView*)m_wndSplitter2.GetPane(1,0));
return TRUE;
}
CCreateContext* pContext)
{
// 产生静态分裂视窗,将参数一的句柄视图窗口分为横列为 1,纵行为 2。
m_wndSplitter1.CreateStatic(this, 1, 2);
// 产生分裂视窗的第一个窗口(标号 0,0)的 view 视窗,采用 CTextView。
m_wndSplitter1.CreateView(0, 0, RUNTIME_CLASS(CTextView),CSize(300, 0), pContext); // 产生第二个分裂视窗,横列为2 纵行为1。位在第一个分裂视窗的(0,1)窗口
m_wndSplitter2.CreateStatic(&m_wndSplitter1, 2, 1,WS_CHILD | WS_VISIBLE, m_wndSplitter1.IdFromRowCol(0, 1));
// 产生第二个分裂视窗的第一个窗口(标号 0,0)的 view 视窗,采用 CBarView。
m_wndSplitter2.CreateView(0, 0, RUNTIME_CLASS(CBarView),CSize(0, 150), pContext);
// 产生第二个分裂视窗的第二个窗口(标号 1,0)的 view 视窗,采用 CGraphView。
m_wndSplitter2.CreateView(1, 0, RUNTIME_CLASS(CGraphView),CSize(0, 0), pContext);//CSize(0, 0)就是剩余的空间大小 // 设定 active pane
SetActiveView((CView*)m_wndSplitter2.GetPane(1,0));
return TRUE;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询