if ((GetPane(row,col)->IsKindOf(pViewClass))==TRUE) return FALSE;
// Get pointer to CDocument object so that it can be used in the creation // process of the new view CDocument * pDoc= ((CView *)GetPane(row,col))->GetDocument(); CView * pActiveView=GetParentFrame()->GetActiveView(); if (pActiveView==NULL || pActiveView==GetPane(row,col)) bSetActive=TRUE; else bSetActive=FALSE; // set flag so that document will not be deleted when view is destroyed pDoc->m_bAutoDelete=FALSE; // Delete existing view ((CView *) GetPane(row,col))->DestroyWindow(); // set flag back to default pDoc->m_bAutoDelete=TRUE;
BOOL CXXXXXXXXXXWnd::ReplaceView(CRuntimeClass * pViewClass)
{
CCreateContext context;
CMainFrame* pMF=(CMainFrame*)AfxGetApp()->GetMainWnd(); CView * pActiveView=pMF->GetActiveView();
CDocument * pDoc= pActiveView->GetDocument(); if ((pActiveView->IsKindOf(pViewClass))==TRUE)
return FALSE;
pActiveView->DestroyWindow();
context.m_pNewViewClass=pViewClass;
context.m_pCurrentDoc=pDoc;
context.m_pNewDocTemplate=NULL;
context.m_pLastView=NULL;
context.m_pCurrentFrame=NULL;
CView * pNewView= (CView *)CreateView(&context);
pMF->SetActiveView(pNewView);
pNewView->SendMessage(WM_PAINT);
return TRUE;
}
---------------------------------------------------------
一般都是多是一个左右切分过的情况,那样的就好办,现成的函数:
BOOL CXXXXXXWnd::ReplaceView(int row, int col,CRuntimeClass * pViewClass,SIZE size)
{ //CXXXXXXWnd是基于CSplitterWnd的!!!!
CCreateContext context;
BOOL bSetActive;
if ((GetPane(row,col)->IsKindOf(pViewClass))==TRUE)
return FALSE;
// Get pointer to CDocument object so that it can be used in the creation
// process of the new view
CDocument * pDoc= ((CView *)GetPane(row,col))->GetDocument();
CView * pActiveView=GetParentFrame()->GetActiveView();
if (pActiveView==NULL || pActiveView==GetPane(row,col))
bSetActive=TRUE;
else
bSetActive=FALSE; // set flag so that document will not be deleted when view is destroyed
pDoc->m_bAutoDelete=FALSE;
// Delete existing view
((CView *) GetPane(row,col))->DestroyWindow();
// set flag back to default
pDoc->m_bAutoDelete=TRUE;
// Create new view
context.m_pNewViewClass=pViewClass;
context.m_pCurrentDoc=pDoc;
context.m_pNewDocTemplate=NULL;
context.m_pLastView=NULL;
context.m_pCurrentFrame=NULL;
CreateView(row,col,pViewClass,size, &context);
CView * pNewView= (CView *)GetPane(row,col);
if (bSetActive==TRUE)
GetParentFrame()->SetActiveView(pNewView);
RecalcLayout();
GetPane(row,col)->SendMessage(WM_PAINT);
return TRUE;
}===========================================================