先初始化新的view再删除旧的view就可以了 void CMainFrame::OnChangeView(CSplitterWnd *pSplitter, int row, int col, CRuntimeClass *pViewClass)
{
// TODO: Add your command handler code here
CWnd *pOldPane = pSplitter->GetPane(row, col);
if (pOldPane->IsKindOf(pViewClass))
{
return;
} CRect rect;
pOldPane->GetWindowRect(rect); CView *pCurrentView = (CView *)pOldPane; CDocument *pDoc = pCurrentView->GetDocument(); BOOL pAutoDel = pDoc->m_bAutoDelete;
pDoc->m_bAutoDelete = FALSE; pOldPane->DestroyWindow(); pDoc->m_bAutoDelete = pAutoDel; CCreateContext pContext;
pContext.m_pNewDocTemplate = NULL;
pContext.m_pLastView = NULL;
pContext.m_pCurrentFrame = this; pContext.m_pNewViewClass = pViewClass;
pContext.m_pCurrentDoc = pDoc; pSplitter->CreateView(row, col, pViewClass, rect.Size(), &pContext);
CWnd *pNewPane = pSplitter->GetPane(row, col); pSplitter->ScreenToClient(rect);
pNewPane->MoveWindow(rect, TRUE);
CActListView *pActView = (CActListView *)pNewPane;
pActView->OnInitialUpdate();
m_pViewClass = pViewClass;
return;
}
{
// TODO: Add your command handler code here
CWnd *pOldPane = pSplitter->GetPane(row, col);
if (pOldPane->IsKindOf(pViewClass))
{
return;
} CRect rect;
pOldPane->GetWindowRect(rect); CView *pCurrentView = (CView *)pOldPane; CDocument *pDoc = pCurrentView->GetDocument(); BOOL pAutoDel = pDoc->m_bAutoDelete;
pDoc->m_bAutoDelete = FALSE; pOldPane->DestroyWindow(); pDoc->m_bAutoDelete = pAutoDel; CCreateContext pContext;
pContext.m_pNewDocTemplate = NULL;
pContext.m_pLastView = NULL;
pContext.m_pCurrentFrame = this; pContext.m_pNewViewClass = pViewClass;
pContext.m_pCurrentDoc = pDoc; pSplitter->CreateView(row, col, pViewClass, rect.Size(), &pContext);
CWnd *pNewPane = pSplitter->GetPane(row, col); pSplitter->ScreenToClient(rect);
pNewPane->MoveWindow(rect, TRUE);
CActListView *pActView = (CActListView *)pNewPane;
pActView->OnInitialUpdate();
m_pViewClass = pViewClass;
return;
}
是不是可以这样:
初始时创建你想要CView2对象,并且Hide;在需要时,Hide CView1对象,Show CView2对象。
http://www.codeguru.com/doc_view/index.shtml