Click to See Complete Forum and Search --> : Question on sample doc/view sample?


ericJA
April 16th, 1999, 08:44 PM
I have a book called Windows 98 How To and in it has a sample on loading a view frame, and I understand it but have a question on it:
In the a menu it loads the frame like so:

in the
void CCh92App::InitInstance()
{
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_CH92TYPE,
RUNTIME_CLASS(CCh92Doc),
RUNTIME_CLASS(CMDIChildWnd), // standard MDI child frame
RUNTIME_CLASS(CCh92View));
AddDocTemplate(pDocTemplate);

pDocTemplate1 = new CMultiDocTemplate(
IDR_CH92TYPE,
RUNTIME_CLASS(CCh92Doc),
RUNTIME_CLASS(CMDIChildWnd), // standard MDI child frame
RUNTIME_CLASS(CDialogView));
AddDocTemplate(pDocTemplate1);
...
...
}


I understandt that this code loads the frame, but what I cant find in
the code is the deletion of the instance doc. I remember somewhere that on a doc/view architecture MFC takes care of deleting the instance for you.
void CCh92App::OnDisplayFormWindow()
{
CCh92Doc *doc = new CCh92Doc("Form Window");
CFrameWnd *wnd = pDocTemplate1->CreateNewFrame(doc, NULL);
pDocTemplate1->InitialUpdateFrame(wnd, doc, TRUE);
}

Is this correct in my assumption, or do I have to delete it.

Thanks

Roger Osborn
April 18th, 1999, 10:53 AM
You are right in thinking that the system does it for you. Normally when you close a window it will go through CFrameWnd::OnClose() which works out if there are any other frame windows open on the document. If not then it calls CDocument::OnCloseDocument() which ultimately does a delete this.
If you want to see the grisly details those functions (like most of MFC) are available to look at in the MFC\SRC directory of your installation.


Cheers,
Roger