|
-
April 21st, 2011, 04:50 AM
#1
Automatically create multiple doc/view in MDI in MFC
Hi.
How do I create multiple document/views at the start of the program?
I would prefer it as a doc/view list with IDs that I can access from other part of the program.
For example I have a MenuBar with "Create 2x2" and I would like to dynamically create 4 doc/views
in 2x2 matrix with each showing different data based on the doc that belongs to it.
Also how do I disable automatic creation of the first view?
You just divided by zero, didn't you?
-
April 21st, 2011, 05:20 AM
#2
Re: Automatically create multiple doc/view in MDI in MFC
 Originally Posted by Odiee
Also how do I disable automatic creation of the first view?
I guess you mean the automatic open of the first doc (and the first view) which is usually done if no comannd line parameter has been given?
Then, in your app's class InitInstance function search for the call of "ParseCommandLine(cmdInfo);" and add a line after it:
Code:
ParseCommandLine(cmdInfo);
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
To create a new doc programmatically:
From any function of your app do the following:
Code:
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate* pT = GetNextDocTemplate(pos);
CDocument* pDoc = pT->OpenDocumentFile(NULL);
Note: This will create a new doc of the first doc template class. If you're using more then one doc templates (not by default on wizzard created MDI app's) you'll need to add some more stuff.
Hope that helps
With regards
Programartist
-
April 21st, 2011, 05:24 AM
#3
Re: Automatically create multiple doc/view in MDI in MFC
First, handle ID_FILE_NEW command in your CWinApp-derived class and do nothing inside.
Next, loop into document templates list and create the documents and frames as you wish.
Example:
Code:
void CMyMDIApp::OnOpenAllViews()
{
POSITION posDocTemplate = GetFirstDocTemplatePosition();
while(NULL != posDocTemplate)
{
CDocTemplate* pDocTemplate = GetNextDocTemplate(posDocTemplate);
POSITION posDoc = pDocTemplate->GetFirstDocPosition();
if(NULL == posDoc)
{
pDocTemplate->OpenDocumentFile(NULL);
}
}
}
[ Later edit ]
I've noticed that assigning CCommandLineInfo::FileNothing to cmdInfo.m_nShellCommand, suggested by ProgramArtist is more elegant than handling ID_FILE_NEW.
Last edited by ovidiucucu; April 21st, 2011 at 05:37 AM.
-
April 21st, 2011, 07:42 AM
#4
Re: Automatically create multiple doc/view in MDI in MFC
That's exactly what I was looking for.
Thanks!
You just divided by zero, didn't you?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|