也就是把单文档变成能够具有多文档的功能,使用单文档与多个视图进行数据的通信连接存储,该怎么解决????

解决方案 »

  1.   

    单文档与多个视图连接存储充分的体现了doc/view的优点。也就是说一份数据,可以使用多种方式表现给用户看。视图有多个,文档类型只有一个这和多文档是不一样的,多文档里面可以有多个Document
      

  2.   

    CDocument::AddView()
    CView::GetDocument()
      

  3.   

    void CMainFrame::OnViewChange(UINT nCmdID)
    {        CView* pViewAdd=NULL;
             CView* pViewRemove=NULL;
      
             CDocument* pDoc = GetActiveDocument();
       
             if((nCmdID == IDM_VIEW_0) && (m_currentView == 0))
             return;
             if((nCmdID == IDM_VIEW_1) && (m_currentView == 1))
             return;
             if((nCmdID == IDM_VIEW_2) && (m_currentView == 2))
             return;
             if(nCmdID == IDM_VIEW_1)
               {
               if (m_pView1 == NULL)
           {
                    m_pView0 = (CTest001View*)GetActiveView();
                    m_pView1 = new CTest001View1;
                    m_pView1->MyCreate(NULL, NULL, AFX_WS_DEFAULT_VIEW,
                    rectDefault, this, AFX_IDW_PANE_FIRST + 1, NULL);        
                   }
               if(m_pLastView==NULL)
                  {
            m_pLastView=m_pView;
                  }
              else
                  { 
            pViewRemove=m_pLastView;
                  }                pViewRemove = m_pLastView;
                    pViewAdd = m_pView1;
                    m_currentView= 1;
                    m_pLastView=m_pView1;
                  }
          else if(nCmdID == IDM_VIEW_2)
             {
     
     if (m_pView2 == NULL)
         {
                  m_pView = (CTest001View*)GetActiveView();
                  m_pView2 = new CTest001View2;
                  m_pView2->MyCreate(NULL, NULL, AFX_WS_DEFAULT_VIEW,
                  rectDefault, this, AFX_IDW_PANE_FIRST + 1, NULL);              }
    if(m_pLastView==NULL)
        { 
    m_pLastView=m_pView;
        }
    else
        {
    pViewRemove=m_pLastView;
        }
        pViewRemove=m_pLastView;
                pViewAdd = m_pView2;
                m_currentView= 2;
                m_pLastView=m_pView2;
          }
     
          else if(nCmdID == IDM_VIEW_0)
              {
              m_pView = (CTest001View*)GetActiveView();
              m_pView2 = new CTest001View2;
              m_pView2->MyCreate(NULL, NULL, AFX_WS_DEFAULT_VIEW,
                  rectDefault, this, AFX_IDW_PANE_FIRST + 1, NULL);               if(m_pLastView==NULL)
      { 
    m_pLastView=m_pView;
      }
    else
      {
    pViewRemove=m_pLastView;
      }          pViewRemove = m_pLastView;
              pViewAdd = m_pView0;
              m_currentView= 0;
              m_pLastView=m_pView0;
      
             }
          else
          return;      int nSwitchChildID = pViewAdd->GetDlgCtrlID();
          pViewAdd->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
          pViewRemove->SetDlgCtrlID(nSwitchChildID);      pViewAdd->ShowWindow(SW_SHOW);
          pViewRemove->ShowWindow(SW_HIDE);      pDoc->AddView(pViewAdd);
          pDoc->RemoveView(pViewRemove);      SetActiveView(pViewAdd);
          RecalcLayout();}
      

  4.   

    上面发的是3视图切换
    这是2视图切换(MSDN上有)
    BOOL CMainFrame::OnViewChange(UINT nCmdID)
    // There is an ON_COMMAND_RANGE message map entry associated with
    // OnViewChange:
    // ON_COMMAND_RANGE( ID_VIEW_VIEW1, ID_VIEW_VIEW2, OnViewChange)
    {
     CView* pViewAdd;
     CView* pViewRemove;
     CDocument* pDoc = GetActiveDocument(); if((nCmdID == ID_VIEW_VIEW1) && (m_currentView == 1))
        return;
     if((nCmdID == ID_VIEW_VIEW2) && (m_currentView == 2))
       return; if (nCmdID == ID_VIEW_VIEW2)
     {
      if (m_pView2 == NULL)
      {
       m_pView1 = GetActiveView();
       m_pView2 = new CMyView2;//Note that if OnSize has been overridden in CMyView2 
    //and GetDocument() is used in this override it can 
    //cause assertions and, if the assertions are ignored,
    //cause access violation.
      
       m_pView2->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
          rectDefault, this, AFX_IDW_PANE_FIRST + 1, NULL);
      }
       pViewAdd = m_pView2;
       pViewRemove = m_pView1;
       m_currentView= 2;
     }
     else
     {
      pViewAdd = m_pView1;
      pViewRemove = m_pView2;
      m_currentView= 1;
     }
         
    // Set the child i.d. of the active view to AFX_IDW_PANE_FIRST,
    // so that CFrameWnd::RecalcLayout will allocate to this 
    // "first pane" that portion of   the frame window's client area 
    // not allocated to control   bars.  Set the child i.d. of the 
    // other view to anything other than AFX_IDW_PANE_FIRST; this
    // examples switches the child id's of the two views. int nSwitchChildID = pViewAdd->GetDlgCtrlID();
     pViewAdd->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
     pViewRemove->SetDlgCtrlID(nSwitchChildID); // Show the newly active view and hide the inactive view. pViewAdd->ShowWindow(SW_SHOW);
     pViewRemove->ShowWindow(SW_HIDE); // Connect the newly active view to the document, and
     // disconnect the inactive view.
     pDoc->AddView(pViewAdd);
     pDoc->RemoveView(pViewRemove); SetActiveView(pViewAdd);
     RecalcLayout();
    }