我需要在多文档程序中完成如下的功能:在一个已经产生的视图的菜单中,通过点击菜单项产生一个新的视图,这个新的视图关联到当前视图的文档上,我用了如下的代码:
void CTestView::OnNewView() 
{
// TODO: Add your command handler code here
CMDIFrameWnd* pMainWnd = ((CMDIFrameWnd*)AfxGetMainWnd());
CMDIChildWnd* pChild = (CMDIChildWnd*)pMainWnd->MDIGetActive();
CTestView* pOldView = (CTestView*)pChild->GetActiveView();

CRuntimeClass* pNewViewClass = RUNTIME_CLASS(CMyView);
CMyView* pNewView = (CMyView*)pNewViewClass->CreateObject(); CTestDoc* m_pDoc = (CTestDoc*)pMainWnd->GetActiveDocument();
pOldView->ShowWindow(SW_HIDE); CCreateContext context;
context.m_pNewViewClass = pNewViewClass;
context.m_pCurrentDoc = m_pDoc;
context.m_pLastView = NULL;
context.m_pCurrentFrame = NULL;
context.m_pNewDocTemplate = NULL;
if(!pNewView->Create(NULL,"new view",AFX_WS_DEFAULT_VIEW,CRect(0,0,0,0),pChild,AFX_IDW_PANE_FIRST,&context))
{
MessageBox("fail!");
pNewView = NULL;
return;
} pNewView->OnInitialUpdate();
pChild->RecalcLayout();
return;
}
但是每次都只是看见一个视图,就好像刚创建的视图替代了当前视图一样?不知是何故?我就使想从菜单项中产生新的视图,该怎么做呢?