CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    22

    How can I bring a selected view window to the top?

    I got a treeview holding the path of all the opened files. I can selected a
    file path by double clicking an item of the
    treeview. My problem is: how can I bring the
    view window associated with the selected file to the top like MS VC++ does? I wrote the following
    code overrided when double clicking
    on an item of the treeview but this seems not work:

    void CMainFrame::SetActiveWindow()
    {
    CString strDocName,strDocPath;
    CDocTemplate* pSelectedTemplate;
    CDocument* pSelectedDoc;
    CMyView* pView;
    POSITION posd,posv;
    POSITION pos=AfxGetApp()->GetFirstDocTemplatePosition();
    CMyTreeView* TreeCtrl=GetTreeViewFile(); // get a pointer to my treeview
    CString strfilepath=TreeCtrl->GetFilePath();
    while(pos!=NULL) {
    pSelectedTemplate=(CDocTemplate*)AfxGetApp()->GetNextDocTemplate(pos);
    ASSERT(pSelectedTemplate!=NULL);
    pSelectedTemplate->GetDocString(strDocName,CDocTemplate:ocName);
    posd=pSelectedTemplate->GetFirstDocPosition();
    while(posd!=NULL) {
    pSelectedDoc=(CDocument*)pSelectedTemplate->GetNextDoc(posd);
    ASSERT(pSelectedDoc!=NULL);
    strDocPath=pSelectedDoc->GetPathName();
    if(strDocPath==strfilepath) {
    // Iterating for views
    posv=pSelectedDoc->GetFirstViewPosition();
    while(posv!=NULL) {
    pView=(CMyView*)pSelectedDoc->GetNextView(posv);
    ASSERT(pView!=NULL);
    pView->SetActiveWindow();
    pView->BringWindowToTop();
    pSelectedDoc->UpdateAllViews(NULL);
    }
    }
    }
    }
    }



    I appricate your suggestions.








  2. #2
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: How can I bring a selected view window to the top?

    First, trace through the routine and verify that your document IS being matched correctly.

    Second, I think the MFC framework doesn't like people trying to manipulate views directly - because they are embedded in frames. Once you have got the view pointer, call its GetParentFrame() method and then activate THAT window. I think that might work better.

    The moral of this story is: if you want to manipulate a view, try to see if you can manipulate its frame in the same way instead, to achieve the same result. It stands more chance of success. For example, trying to size a view will probably not work correctly - resize its frame instead.

    Does this help?



    --
    Jason Teagle
    [email protected]

  3. #3
    Join Date
    May 1999
    Posts
    22

    Re: How can I bring a selected view window to the top?


    Many thanks, Jason. It works!!




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured