我在编写多文档程序时候,碰到一个这样的问题:
我在程序中添加了三种类型文档,现在我需要遍历所有的文档和视图,现在我只会遍历当前活动文档的多个视图,但对于其他文档的指针及其视图访问不到,请大侠们指点,希望有很好的实例,谢谢!

解决方案 »

  1.   

    Example// This example uses CDocument::GetFirstViewPosition
    // and GetNextView to repaint each view.   POSITION pos = GetFirstViewPosition();
       while (pos != NULL)
       {
          CView* pView = GetNextView(pos);
          if( DYNAMIC_DOWNCAST(xxView,pView) != NULL ) 
          {
              // do something
          }
          pView->UpdateWindow();
       }   xxView:  你想操作的VIEW   
      

  2.   

    CDocument* pDoc = GetActiveDocument(); CString str = pDoc->GetTitle();
    if(str.CompareNoCase(m_strDocName) == 0)
    return;
    POSITION pos = pDoc->GetFirstViewPosition();
    while(pos != NULL)
    {
    CView* pView = pDoc->GetNextView(pos);
    pDoc=pView->GetDocument();
    str = pDoc->GetTitle();
    if(str.CompareNoCase(m_strDocName) == 0)
    {
    SetActiveView(pView,FALSE);
    return;
    }
    }
    这是我写代码,它只能获得当前文档的多个视图指针,但不能获得其他类型文档的指针呀,在我的应用程序里面定义了三种文档类型。