请问在单文档中怎样实现多个表视(非拆分窗口):即在工具栏中通过三个按纽实现对三个表视的切换,请付已源码。谢谢

解决方案 »

  1.   

    切换视图:
    void CMainFrame::SwitchView(UINT nViewID)
    {
      CView *pOldActiveView =GetActiveView();
      CView *pNewActiveView=(CView*)GetDlgItem(nViewID);
      if(pNewActiveView==NULL)
      {
    switch(nViewID)
    {
      case IDD_RECORD_VIEW:
    pNewActiveView=new CResultView();
    break;
      case IDD_USELISTVIEW_FORM:
    pNewActiveView=new CUseListViewView();
    break;
      case ID_MAIN_VIEW:
    pNewActiveView=new CWordRecordView();
    break;
    }
      
      CCreateContext context;
      context.m_pCurrentDoc=pOldActiveView->GetDocument();
      //add the flag:WS_BORDER,or the view will capture all the client included the windowrect!
      pNewActiveView->Create(NULL,NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,CFrameWnd::rectDefault,this,nViewID,&context);
      pNewActiveView->OnInitialUpdate();
      }
      SetActiveView(pNewActiveView);
      pNewActiveView->ShowWindow(SW_SHOW);
      pOldActiveView->ShowWindow(SW_HIDE);
      //I use the win32 based function:SetWindowLong() instead of the older style:SetWindowWord()
      ::SetWindowLong(pNewActiveView->m_hWnd,GWL_ID,AFX_IDW_PANE_FIRST);
      this->RecalcLayout();
      delete pOldActiveView;
    }void CMainFrame::OnFormview() 
    {
    // TODO: Add your command handler code here
    this->SwitchView(ID_MAIN_VIEW);
    }void CMainFrame::OnMainview() 
    {
    // TODO: Add your command handler code here
    this->SwitchView(IDD_USELISTVIEW_FORM);
    }void CMainFrame::OnResultview() 
    {
    // TODO: Add your command handler code here
    this->SwitchView(IDD_RECORD_VIEW);
    }
    ——————————————————————————————