BOOL CMDIApp::OnIdle(LONG lCount)
{
// TODO: Add your specialized code here and/or call the base class
if (app)
{
app->Run();
}
return CWinApp::OnIdle(lCount);
}
Thanks guys for answering my previous questions, I managed to create the object as single instance and there is no problem. Thanks a lot. However, I have some difficulty with the following problem. As shown above, the application (as a single instance, I should have named it something else ), is completely engaged in rendering and ignores all messages toward other MDI child windows. So the result is a plain window which looks like a SDI.
See mdi1.png
Which is supposed to look like mdi2.png
Does anyone know how to alter the program to make it look exactly like picture 2 while
preserving dx functionalities?
Thanks
Jack
Last edited by lucky6969b; December 7th, 2010 at 03:02 AM.
Reason: Want to reattach the pictures
I asume that 'Hello 1' and 'Bounce 1' are different documents and not only different views on the same document.
If so, you would need two frame classes, two doc classes and two view classes. For the second triple of frame, doc and view you would use a second doc template in order to create them. That is done in the InitInstance function of your app class.
The above would mean that beside of the mainframe class you have two further frame classes both derived from CMDIChildWnd and both equipped with an own menu (which would replace the one in main frame).
A smaller solution only would create a second document with a further call of OnFileNew and show the views for both documents non-maximized. Actually that is only SDI and not MDI cause the latter implies multiple document types rather than multiple documents.
The above would mean that beside of the mainframe class you have two further frame classes both derived from CMDIChildWnd and both equipped with an own menu (which would replace the one in main frame).
A smaller solution only would create a second document with a further call of OnFileNew and show the views for both documents non-maximized. Actually that is only SDI and not MDI cause the latter implies multiple document types rather than multiple documents.
I wonder SDI could be able to display multiple child windows, not multiple documents(one doc but multiple views). So should I stick with SDI instead? because yes, I have no multiple documents to deal with, just one document but multiple views.
Thanks
Jack
I wonder SDI could be able to display multiple child windows, not multiple documents(one doc but multiple views). So should I stick with SDI instead? because yes, I have no multiple documents to deal with, just one document but multiple views.
No, you should not "stick with SDI instead".
MDI is mush more convenient than SDI allowing you to simultaneously have a lot of frames with one or more Views in each one.
If I plan to use more than one View in my App I always create this App as MDI, not SDI.
I wonder SDI could be able to display multiple child windows, not multiple documents(one doc but multiple views). So should I stick with SDI instead? because yes, I have no multiple documents to deal with, just one document but multiple views.
Thanks
Jack
Actually each wizard-generated MDI project firstly is an SDI project cause it has only one doc template, hence only one frame-doc-view combination is present. Furthermore, some former code you posted used the mainframe as frame class in the doc template and not a second (wizard-generated) frame class derived from CMDIChildWnd. So an MDI project which only provides one document type is already behaving like an SDI and you must not change the base created by the wizard.
For creating a new view for an existing document you may look at the following sample code (of an old but real working project).
Code:
// I added a menu item and a toolbar button for creating a search view for the current document
BEGIN_MESSAGE_MAP(CMaterialItemDoc, CFoodItemDoc)
//{{AFX_MSG_MAP(CMaterialItemDoc)
ON_COMMAND(ID_VIEW_COMPTREE, OnViewCompTree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// that creates a new doc template combining doc, frame and view
CMultiDocTemplate* CMaterialItemDoc::CreateCompSelTemplate()
{
return new CMultiDocTemplate(IDR_TREE,
RUNTIME_CLASS(CMaterialItemDoc),
RUNTIME_CLASS(CFoodChildFrame),
RUNTIME_CLASS(CComponentSelView));
}
// that is the handler which creates the new view
void CMaterialItemDoc::OnViewCompTree()
{
if (m_pCompSelTemplate == NULL)
{
// I store the template in a member
m_pCompSelTemplate = CreateCompSelTemplate();
// my app class has a container which manages all templates
theApp.AddDocTemplate(m_pCompSelTemplate);
}
else
{
// I lookup for the existing view and activate it if existing
POSITION pos = m_pCompSelTemplate->GetFirstDocPosition();
CDocument* pDoc;
if (pos != NULL)
{
pDoc = m_pCompSelTemplate->GetNextDoc(pos);
if (pDoc != NULL)
{
pos = pDoc->GetFirstViewPosition();
CView* pView = pDoc->GetNextView(pos);
if (pView != NULL)
pView->GetParentFrame()->ActivateFrame();
return;
}
}
}
CreateCompSelView();
}
void CMaterialItemDoc::CreateCompSelView()
{
// that creates the frame
CFrameWnd* pFrame = m_pCompSelTemplate->CreateNewFrame(this, NULL);
// that creates the view for the existing doc
m_pCompSelTemplate->InitialUpdateFrame(pFrame, this, TRUE);
}
Bookmarks