|
-
May 27th, 1999, 09:48 AM
#1
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 ????
-
May 27th, 1999, 10:04 AM
#2
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();
}
}
-
May 27th, 1999, 10:15 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|