Creating 2 documents instead of one.
-
This is probably a simple question to answer, but I can't seem to find a solution. I am trying to create two new documents when the user chooses the "File|New" command. I have two document templates set up, and wish to create one of each automatically. Also, how would I go about handling an "File|New Document 2" command - To create a new document from template 2, without showing the user the MFC "new file type" dialog. I hope semobody can help me with my problem. Thanks in advance, David Wulff Battleaxe Software
-
This is probably a simple question to answer, but I can't seem to find a solution. I am trying to create two new documents when the user chooses the "File|New" command. I have two document templates set up, and wish to create one of each automatically. Also, how would I go about handling an "File|New Document 2" command - To create a new document from template 2, without showing the user the MFC "new file type" dialog. I hope semobody can help me with my problem. Thanks in advance, David Wulff Battleaxe Software
#1 First create two new data members in your application class. for example: CMultiDocTemplate* m_pDocTemplate1; CMultiDocTemplate* m_pDocTemplate2; #2 Change the document template registering to something like this. m_pDocTemplate1 = new CMultiDocTemplate( IDR_MYDOC1, RUNTIME_CLASS( CMyDocument1 ), RUNTIME_CLASS( CChildFrame ), RUNTIME_CLASS( CMyView1 ) ); AddDocTemplate( m_pDocTemplate1 ); m_pDocTemplate2 = new CMultiDocTemplate( IDR_MYDOC2, RUNTIME_CLASS( CMyDocument2 ), RUNTIME_CLASS( CChildFrame ), RUNTIME_CLASS( CMyView2 ) ); AddDocTemplate( m_pDocTemplate2 ); #3 Overwrite the "OnFileNew" command handler in your application class. void CMyApp::OnFileNew() { // don't call CWinApp::OnFileNew() // Create a new document from template 1 m_pDocTemplate1->OpenDocumentFile( NULL ); // Create a new document from template 2 m_pDocTemplate2->OpenDocumentFile( NULL ); } That's it. Best regards Holger Persch
-
#1 First create two new data members in your application class. for example: CMultiDocTemplate* m_pDocTemplate1; CMultiDocTemplate* m_pDocTemplate2; #2 Change the document template registering to something like this. m_pDocTemplate1 = new CMultiDocTemplate( IDR_MYDOC1, RUNTIME_CLASS( CMyDocument1 ), RUNTIME_CLASS( CChildFrame ), RUNTIME_CLASS( CMyView1 ) ); AddDocTemplate( m_pDocTemplate1 ); m_pDocTemplate2 = new CMultiDocTemplate( IDR_MYDOC2, RUNTIME_CLASS( CMyDocument2 ), RUNTIME_CLASS( CChildFrame ), RUNTIME_CLASS( CMyView2 ) ); AddDocTemplate( m_pDocTemplate2 ); #3 Overwrite the "OnFileNew" command handler in your application class. void CMyApp::OnFileNew() { // don't call CWinApp::OnFileNew() // Create a new document from template 1 m_pDocTemplate1->OpenDocumentFile( NULL ); // Create a new document from template 2 m_pDocTemplate2->OpenDocumentFile( NULL ); } That's it. Best regards Holger Persch