我是点控制条的树形控件在C***App中用OpenDocumentFile()打开文件,但如果某个文件之前已经打开并显示了,怎样把对应窗口显示到最前面。

解决方案 »

  1.   

    CWinApp::GetFirstDocTemplatePosition/CWinApp::GetNextDocTemplate遍历文档模板列表,
    CDocTemplate::GetFirstDocPosition/CDocTemplate::GetNextDoc遍历文档指针列表,
    根据CDocument::GetPathName得到文件名称比较,找到了就用
    CDocument::GetFirstViewPosition/CDocument::GetNextView找到视图激活。
      

  2.   

    CDocument::GetFirstViewPosition/CDocument::GetNextView找到视图激活
    这一步怎样激活视图到最前面?
      

  3.   

    void ShowChild(CString filename)   //参数为文件名
    {
    int flag = 0;
    POSITION p = pMyApp->GetFirstDocTemplatePosition();
    while (p != NULL) 
    {
     CDocTemplate *pDocTemplate = pMyApp->GetNextDocTemplate(p);
     POSITION p1 = pDocTemplate->GetFirstDocPosition();
     while (p1 != NULL) 
     {
      CDocument *pDocument = pDocTemplate->GetNextDoc(p1);
      POSITION p2 = pDocument->GetFirstViewPosition(); 
      if(filename==pDocument->GetPathName())
        {
        while (p2 != NULL) 
      {
       CView *pView = pDocument->GetNextView(p2);
        flag = 1;
       }
     }
      if(flag==0)
       {m_pDocument->OpenDocumentFile(filename);}
    }这是我按2楼的方法写的显示文件函数,现在文件已经打开过后并不再打开了。
    大家指点下在哪里添加代码可以把找到的视图显示到最前端。
      

  4.   

    CDocument *pDocument = pDocTemplate->GetNextDoc(p1);
      if(filename==pDocument->GetPathName())
        {
      POSITION p2 = pDocument->GetFirstViewPosition(); 
        while (p2 != NULL) 
      {
       CView *pView = pDocument->GetNextView(p2);
          pView->GetParentFrame()->BringWindowToTop();
        flag = 1;
          break;
       }
     }
      

  5.   

    问题已经解决了,谢谢Mackz。我的毕业设计也差不多完成了。