CCreateContext context; context.m_pNewViewClass = pNewViewClass; context.m_pCurrentDoc = GetActiveDocument(); CView* pNewView = STATIC_DOWNCAST(CView, CreateView(&context)); if (pNewView != NULL) { // the new view is there, but invisible and not active... pNewView->ShowWindow(SW_SHOW); pNewView->OnInitialUpdate(); SetActiveView(pNewView); RecalcLayout(); m_nCurrentExample = nCmdID; // finally destroy the old view... pOldActiveView->DestroyWindow(); }
++C++
---------
下去就可以了。可以在类向导中建立相应的视图类,继承相应的类。比如建立列表视图就可继承
CListView类。在Cmainfram.cpp中的
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
CSize size;
CRect rect;
GetClientRect(&rect);
size.cx=rect.Width()/2;
size.cy=rect.Height();
m_wndSplitter.CreateStatic(this,1,2);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CSplitterListView),size,pContext);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CSplitterFormView),size,pContext);
return TRUE;
}
这样定义就可以了。
我这里是定义了两个视图,一是列表视图类CSplitterListView,一是形式视图类CSplitterFormView,这样应该可以了。
程序中有这个实例的指针,操纵它就可以了.
context.m_pCurrentDoc = pOldView->GetDocument();
context.m_pNewViewClass = RUNTIME_CLASS(COpenRefView);
pCurView = STATIC_DOWNCAST(CView, CreateView(&context)); // 最后生成新视图,并设置
ASSERT(pCurView != NULL);
pCurView->OnInitialUpdate();
SetActiveView(pCurView);
pCurView->ShowWindow(SW_SHOW);
pEmpty->ShowWindow(SW_HIDE);
RecalcLayout();
context.m_pNewViewClass = pNewViewClass;
context.m_pCurrentDoc = GetActiveDocument();
CView* pNewView = STATIC_DOWNCAST(CView, CreateView(&context));
if (pNewView != NULL)
{
// the new view is there, but invisible and not active...
pNewView->ShowWindow(SW_SHOW);
pNewView->OnInitialUpdate();
SetActiveView(pNewView);
RecalcLayout();
m_nCurrentExample = nCmdID; // finally destroy the old view...
pOldActiveView->DestroyWindow();
}