The code needed to implement view switching depends on the frame window containing the view. There are three common cases: the view is contained within a CFrameWnd (SDI application), the view is contained within a CMDIChildWnd (MDI application) and the view is a pane of a splitter window, either in SDI or MDI applications. In all cases what we need is a method in our document class to switch to the desired view. This method should receive the new view as a parameter and return the view that was replaced. This returned view is not contained in the document's list anymore. The advantage of having this method in the document class becomes obvious when there are several document types each of which can have different view types. Lets start with an SDI application that doesn't have splitters: 
CView* CMyDocument::SwitchToView ( CView* pNewView )
{
   CFrameWnd* pMainWnd = (CFrameWnd*)AfxGetMainWnd();
   CView* pOldActiveView = pMainWnd->GetActiveView();
   ASSERT(pOldActiveView != NULL);
   ASSERT_VALID(pOldActiveView);
   ASSERT(pOldActiveView->GetDocument() == this); // must be attached to us   /* Set the child window ID of the active view to AFX_IDW_PANE_FIRST.
      This is necessary so that CFrameWnd::RecalcLayout will allocate
      this "first pane" to that portion of the frame window's client
      area not allocated to control bars.  Set the child ID of
      the previously active view to some other ID.
   */   ::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, 0);
   ::SetWindowLong(pNewView->m_hWnd, GWL_ID, AFX_IDW_PANE_FIRST);   // Show the newly active view and hide the inactive view.
   pNewView->ShowWindow(SW_SHOW);
   pOldActiveView->ShowWindow(SW_HIDE);   // Connect the newly active view to the document, and disconnect the inactive view
   AddView(pNewView); 
   RemoveView(pOldActiveView);
   pMainWnd->SetActiveView(pNewView);
   pMainWnd->RecalcLayout();   return pOldActiveView;
}
////CFrameWnd::RecalcLayout will allocate
////this "first pane" to that portion of the frame window's client
////area not allocated to control bars.  
这是注释中的话,我想知道为什么?