void CVisualADSDoc::MyOnClose() { // TODO: 在此添加命令处理程序代码 if (!SaveModified()) return; BOOL bAutoDelete = m_bAutoDelete; m_bAutoDelete = FALSE; // don't destroy document while closing views while (!m_viewList.IsEmpty()) { // get view attached to the document CView* pView = (CView*)m_viewList.GetHead(); ASSERT_VALID(pView); pView->DestroyWindow(); } m_bAutoDelete = bAutoDelete; // clean up contents of document before destroying the document itself DeleteContents(); // delete the document if necessary if (m_bAutoDelete) delete this; }
//----------------------------------------------------------------------------- // Purpose: Replaces the current active view with a given view type. // Input : *pViewClass - // Output : CView //----------------------------------------------------------------------------- CView *CChildFrame::ReplaceView(CRuntimeClass *pViewClass) { // // Verify that there is an active view to replace. // CView *pCurrentView = GetActiveView(); if (!pCurrentView) { return(NULL); } // // If we're already displaying this kind of view, no need to go // further. // if ((pCurrentView->IsKindOf(pViewClass)) == TRUE) { return(pCurrentView); } // // Get pointer to CDocument object so that it can be used in the // creation process of the new view. Set flag so that the document // will not be deleted when view is destroyed. // CMapDoc *pDoc = (CMapDoc *)pCurrentView->GetDocument(); BOOL bAutoDelete = pDoc->m_bAutoDelete; pDoc->m_bAutoDelete=FALSE; int iRow = 0, iCol = 0; CRect rect; // Delete existing view if (bUsingSplitter) { pCurrentView->GetClientRect(rect); m_wndSplitter->GetActivePane(&iRow, &iCol); m_wndSplitter->DeleteView(iRow, iCol); } else { pCurrentView->DestroyWindow(); } // Restore the autodelete flag. pDoc->m_bAutoDelete = bAutoDelete; // Create new view and redraw. CCreateContext context; context.m_pNewViewClass = pViewClass; context.m_pCurrentDoc = pDoc; context.m_pNewDocTemplate = NULL; context.m_pLastView = NULL; context.m_pCurrentFrame=this; CView *pNewView = NULL; if (bUsingSplitter) { if (m_wndSplitter->CreateView(iRow, iCol, pViewClass, rect.Size(), &context)) { pNewView = (CView *)m_wndSplitter->GetPane(iRow, iCol); } } else { pNewView = (CView *)pViewClass->CreateObject(); if (pNewView) { CRect r; GetClientRect(r); if (!pNewView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, r, this, AFX_IDW_PANE_FIRST, &context)) { pNewView = NULL; } } } if (!pNewView) { TRACE0("Warning: couldn't create view for frame\n"); return(NULL); } pNewView->SendMessage(WM_INITIALUPDATE, 0, 0); if (bUsingSplitter) { m_wndSplitter->RecalcLayout(); } return(pNewView); }
//----------------------------------------------------------------------------- // Purpose: // Input : bSplitter - //----------------------------------------------------------------------------- void CChildFrame::SetSplitterMode(BOOL bSplitter) { if(bSplitter == bUsingSplitter) return; // already at this mode if(!bSplitter) { // delete the splitterwnd.. first, get the view that it is currently // using. CView * pActiveView = GetActiveView(); CDocument* pDoc = pActiveView->GetDocument(); BOOL bAutoDelete=pDoc->m_bAutoDelete; pDoc->m_bAutoDelete=FALSE; pActiveView->SetRedraw(FALSE); m_wndSplitter->SetRedraw(FALSE); pActiveView->SetParent(this); m_wndSplitter->DestroyWindow(); delete m_wndSplitter; m_wndSplitter = NULL; pDoc->m_bAutoDelete = bAutoDelete; // redraw active view CRect r; GetClientRect(r); pActiveView->SetRedraw(TRUE); pActiveView->MoveWindow(0, 0, r.right, r.bottom, TRUE); } else { CView * pActiveView = GetActiveView(); Assert(pActiveView); CMapDoc* pDoc = (CMapDoc*) pActiveView->GetDocument(); BOOL bAutoDelete=pDoc->m_bAutoDelete; pDoc->m_bAutoDelete=FALSE; pActiveView->DestroyWindow(); pDoc->m_bAutoDelete = bAutoDelete; // creating new four views. m_wndSplitter = new CMySplitterWnd; if(!m_wndSplitter->CreateStatic(this, 2, 2)) { TRACE0("Failed to create split bar "); return; // failed to create } CRect r; GetClientRect(r); CSize sizeView(r.Width()/2 - 3, r.Height()/2 - 3); CCreateContext context; context.m_pNewViewClass = NULL; context.m_pCurrentDoc = pDoc; context.m_pNewDocTemplate = NULL; context.m_pLastView = NULL; context.m_pCurrentFrame = this; context.m_pNewViewClass = RUNTIME_CLASS(CMapView2D); m_wndSplitter->CreateView(0, 1, RUNTIME_CLASS(CMapView2D), sizeView, &context); m_wndSplitter->CreateView(1, 0, RUNTIME_CLASS(CMapView2D), sizeView, &context); m_wndSplitter->CreateView(1, 1, RUNTIME_CLASS(CMapView2D), sizeView, &context); context.m_pNewViewClass = RUNTIME_CLASS(CMapView3D); m_wndSplitter->CreateView(0, 0, context.m_pNewViewClass, sizeView, &context); } bUsingSplitter = bSplitter; }