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
    2

    How can i access to a View from another view

    I have a question : How can i call a member's function of a view from another view without introduce personal pointers ????


  2. #2
    Join Date
    May 1999
    Location
    Canada
    Posts
    36

    Re: How can i access to a View from another view

    get the doc from current view
    from the doc traverse all views to get the type you want
    cast it to that type
    call the function


    POSITION pos = pDoc->GetFirstViewPosition();

    while (pos != NULL)
    {
    pView = pDoc->GetNextView(pos);
    if (pView->IsKindOf(RUNTIME_CLASS(CView_List)))
    {
    ((CView_List*)pView)->FooBar();
    }
    }





  3. #3
    Join Date
    Apr 1999
    Posts
    383

    Re: How can i access to a View from another view

    You can iterate through all the views associated with a document using CDocument::GetFirstViewPosition() and CDocument::GetNextView(), which returns a CView*. So if the other view belongs to the same document, and you can identify it through its pointer, you can do it that way.

    If the view belongs to another document, you can find it in a similar way by iterating the CDocTemplate, and you can iterate the CDocTemplates via the CWinApp...

    But, an alternative way that fits the MFC Doc/View model rather better, is to do it indirectly by calling CDocument::UpdateAllViews(). This takes a pointer to the calling view, and two 'hint' arguments (you decide what they contain), and it calls OnUpdate() on every other view associated with the document, passing the caller view pointer and the hint arguments.

    If you pass a hint value that only the target view will recognise, it can call the function you require in its OnUpdate() method.

    This is the preferred technique for communicating between a document's views.

    Dave


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