|
|
|
NEWBIE TIP #6 Getting from a view to the document, and vice-versa
Remember that there is a one-to-many mapping from CDocument to CView.
That means that while a document can have many views, a view has but
one (exactly one) document. Think of the Scribble app (and
shame on you if you never tried to follow along with it Since every view must have one and only one document, it stands to reason that it has a data member dedicated for just that purpose. It's m_pDocument. When AppWizard creates a derived document class for you, it creates an inline function called GetDocument, which returns a type-safe pointer to your document object. If you have more than one view, you update them using the CDocument::UpdateAllViews function. If you really want to iterate through all your views manually, use the CDocument::GetFirstViewPosition and the CDocument::GetNextView functions as illustrated in the code below.
See also Chapter 15 of David Kruglinski's excellent book, Inside Visual C++ Version 4.
Source code | Past Tips | Future Tips | Home | Comments on this Tip?
Send us mail.
Got an idea for a Tip you'd like us to write?
Let us know.
Solved a problem lately that would make a good Tip?
PLEASE tell us about it!!!
|