Re: MDI in MFC, Conceptually

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Scott McPhillips [MVP] (org-dot-mvps-at-scottmcp)
Date: 02/06/05


Date: Sun, 06 Feb 2005 12:11:25 -0500

Roger Lakner wrote:
> Well, its nice to know I'm not too far off base, but I'm still puzzled
> by something and it relates to what I alluded to in my original
> message. Let me be more specific. A View's access to the Document's
> data is through a pointer (say, pDoc). The View uses this pointer to,
> in my case, render the BMP file data in a window and this is typically
> done in OnDraw using pDC. This is easy (using GDI or GDI+ routines)
> for the first file I open. When I open the second file, pDoc now
> points to the new file data, the new window renders the second image,
> but because pDoc now points to the new data, when the first window
> which contained the image from the first file receives the OnUpdate
> message, OnDraw renders the image that pDoc now points to, which is
> the second image. So now I have the second image in both windows --
> not what I want. This behavior makes sense if your App contains two
> Views of the same Document (as most of the examples demonstrate), but
> it seems to me that MFC is not good when you want to display multiple
> documents simultaneously. Or am I missing something?
>
> Roger

Yes, either you are missing something or you have coded something
incorrectly. Each view has a document pointer member variable that is
initialized by the framework when the view is created. Each view's
GetDocument function gets its own document pointer. It retrieves
whichever document created that particular view.

-- 
Scott McPhillips [VC++ MVP]