I have an MDI application where a dialog is called when the OnFileNew() function (processed by the theApp object) is called. This dialog allows the user to set values to some variables that then need to be passed on to the CChildFrame object that is created when the ->CreateNewChild() function is called.

How do I pass these variables onto the CChildFrame object that is created by the ->CreateNewChild() function?

EDIT:
In response to an answer I got, here are the results for using ->Create() vs ->CreateNewChild().

1 Answer
1

You can pass the data via a customized document template. Derive a class from CMultiDocTemplate to add additional data members, then add a pointer to your derived document template class to your CWinApp-derived app class. Initialize your document template in the usual way, except when you finish, save the new document template object to the pointer in your app class.

Now in your CreateNewChild function, instead of calling CWinApp::OnFileNew, you can just get the data from the current frame, then assign to the data member in the document template saved in the app class, before calling OpenDocumentFile(NULL). You can clear the data members when OpenDocumentFile returns.

The document template will in turn create the child frame and pass the doc template in the create context. To get the create context in the child frame, you can either override CChildFrame::OnCreateClient, or read the create structure in OnCreate:

Instead of passing the initialization data in the document template, you could also pass data to the new document. You will basically copy the code from CMultiDocTemplate::OpenDocumentFile and add the code to get the initialization data from the active document of the main frame.

Is there a way to do this when there is no Document/Architecture Support in the project?
–
Timothy ChapmanJun 10 '13 at 12:30

You can pass a class derived from CCreateContext that contains your initial data gathered in the ID_FILE_NEW command handler to the create function of the child frame, and use the create context to populate your child frame in OnCreate.
–
Sheng Jiang 蒋晟Jun 10 '13 at 16:54