(转)视口切换技术

在windows中,当需要显示多个实时的视口时,视图之间的切换是不可避免的,以下为

一个事例:

CMainFrame::SwitchToView(eView nView)
{
 CAD_HOC_Doc *pDoc = (CAD_HOC_Doc*)GetActiveDocument();
    CView* m_pOldView=GetActiveView();
    switch (nView) {
  case GRAPHIC:
    if(m_pOldView->IsKindOf(RUNTIME_CLASS(CAD_HOC_View))!=0)
     MessageBeep(-1);
    else{
    m_pOldView->ShowWindow(SW_HIDE);
    m_pGraphView->ShowWindow(SW_SHOW);
    m_pGraphView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
    m_pOldView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
    SetActiveView(m_pGraphView);
    this->RecalcLayout();
    }
    break;
  case STATISTIC:
    if(m_pStatisticView==0)
    {
     m_pStatisticView=(CView *)new CAdHocStatisticView;
     CCreateContext context;
     context.m_pCurrentDoc = pDoc;
     m_pStatisticView->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,rectDefault,this,AFX_IDW_PANE_FIRST+1, &context);
    }  
    if(m_pOldView->IsKindOf(RUNTIME_CLASS(CAdHocStatisticView))!=0)
     MessageBeep(-1);
    else
    {
    m_pOldView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
    m_pStatisticView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
    m_pStatisticView->ShowWindow(SW_SHOW);
    m_pOldView->ShowWindow(SW_HIDE);
    SetActiveView(m_pStatisticView);
    this->RecalcLayout();
    }
    break;

  case DROP:
             if(m_pDrop==0)
    {
       m_pDrop=(CView *)new COutput_Drop;
       CCreateContext context;
       context.m_pCurrentDoc= pDoc;
       m_pDrop->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,rectDefault,this,AFX_IDW_PANE_FIRST+1, &context);
    }
    if(m_pOldView->IsKindOf(RUNTIME_CLASS(COutput_Drop))!=0)
     MessageBeep(-1);
    else
    {
    m_pOldView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
    m_pDrop->SetDlgCtrlID(AFX_IDW_PANE_FIRST);   
    m_pDrop->ShowWindow(SW_SHOW);
    m_pOldView->ShowWindow(SW_HIDE);
    SetActiveView(m_pDrop);
    this->RecalcLayout();
    }
    break; 
  case PTOPDELAY:
       if(m_pPtopdelay==0)
      {
      m_pPtopdelay=(CView *)new COutput_Ptopdelay;
       CCreateContext context;
       context.m_pCurrentDoc= pDoc;
       m_pPtopdelay->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,rectDefault,this,AFX_IDW_PANE_FIRST+1, &context);
      }
                if(m_pOldView->IsKindOf(RUNTIME_CLASS(COutput_Ptopdelay))!=0)
     MessageBeep(-1);
    else
    {
    m_pOldView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
    m_pPtopdelay->SetDlgCtrlID(AFX_IDW_PANE_FIRST);   
    m_pPtopdelay->ShowWindow(SW_SHOW);
    m_pOldView->ShowWindow(SW_HIDE);
    SetActiveView(m_pPtopdelay);
    this->RecalcLayout();
    }
    break;
  case THROUGHPUT:
       if(m_pThroughput==0)
      {
      m_pThroughput=(CView *)new COutput_Throughput;
       CCreateContext context;
       context.m_pCurrentDoc= pDoc;
       m_pThroughput->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,rectDefault,this,AFX_IDW_PANE_FIRST+1, &context);
      }
    if(m_pOldView->IsKindOf(RUNTIME_CLASS(COutput_Throughput))!=0)
     MessageBeep(-1);
    else
    {
    m_pOldView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
    m_pThroughput->SetDlgCtrlID(AFX_IDW_PANE_FIRST);   
    m_pThroughput->ShowWindow(SW_SHOW);
    m_pOldView->ShowWindow(SW_HIDE);
    SetActiveView(m_pThroughput);
    this->RecalcLayout();
    }
    break;
   case JITTER:
       if(m_pJitter==0)
      {
      m_pJitter=(CView *)new COutput_Jitter;
       CCreateContext context;
       context.m_pCurrentDoc= pDoc;
       m_pJitter->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,rectDefault,this,AFX_IDW_PANE_FIRST+1, &context);
      }
    if(m_pOldView->IsKindOf(RUNTIME_CLASS(COutput_Jitter))!=0)
     MessageBeep(-1);
    else
    {
    m_pOldView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
    m_pJitter->SetDlgCtrlID(AFX_IDW_PANE_FIRST);   
    m_pJitter->ShowWindow(SW_SHOW);
    m_pOldView->ShowWindow(SW_HIDE);
    SetActiveView(m_pJitter);
    this->RecalcLayout();
    }
    break;
 } 
}

posted @ 2010-01-04 16:08  大笨狼  阅读(650)  评论(0)    收藏  举报