Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Creating 2 documents instead of one.

Creating 2 documents instead of one.

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++wpfquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David Wulff
    wrote on last edited by
    #1

    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

    H 1 Reply Last reply
    0
    • D David Wulff

      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

      H Offline
      H Offline
      HP
      wrote on last edited by
      #2

      #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

      L 1 Reply Last reply
      0
      • H HP

        #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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Thanks. It is so simple, yet I spent ages doing everything but that. I was thinking more along the lines of creating the new document, manually by creating the frame, view, etc - but this is all I need! Thanks again,

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups