How to Help Your Business Become an AI Early Adopter
This demo app shows how to create an (MDI) app whereby opening or creating a new document automatically shows both views. The only drawback to this is that if you use the New Window item on the Window menu, it always creates just one view - the first type. I'm sure that can be resolved by someone if necessary.
Also, closing one child frame will not automatically close the other - this behaviour might be desirable if the user only wants to see the one view; if not, then that will need some work.
1. Create a second view class for the second type of data display (using ClassWizard).
2. Construct a second CMultiDocTemplate in CWinApp::InitInstance(), using the second view class and the same document and child frame as the first. Store its pointer in the app class, but do NOT call CWinApp::AddDocTemplate() with this one - otherwise the app will ask the user what type of doc to create whenever you try to create a new document.
3. In CWinApp::ExitInstance(), delete this second doc template as it does not get automatically deleted like the first one does (because it was not added to the app).
4. In the document's OnNewDocument(), get a pointer to the second template from the app object, and then call CreateNewFrame() and InitialUpdateFrame() (in that order) with this doc template; use the document's 'this' pointer for the document to use (so that the second view shares the first document), and NULL for the frame window (since the first MDI child frame does not exist when OnNewDocument() is called - this does not matter). The frame pointer to use in InitialUpdateFrame() is the return value from CreateNewFrame().
Note: As both views share the same document, OnNewDocument() only gets called once per document - therefore the above method of automatically creating the second frame will not cause any problems.
5. Each view can now do its own drawing based on the data in the document. Note that the second view will refer to a generic CDocument pointer, which you will have to cast to the correct document class.