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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to use "OnNewDocument" from cview or cmainframe class

how to use "OnNewDocument" from cview or cmainframe class

Scheduled Pinned Locked Moved C / C++ / MFC
comtutorialquestion
4 Posts 2 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.
  • C Offline
    C Offline
    chaitannya_m
    wrote on last edited by
    #1

    Hi everyone, I am using an activex control which i have inserted onto a formview of an mdi application.when i press File->new option i get a new window with the activex in it. Now i want to implement the same funtionality on a button press. i want the same results as that of File->New.How do i achieve it from the CFormView or the Cmainframe class.

    M 1 Reply Last reply
    0
    • C chaitannya_m

      Hi everyone, I am using an activex control which i have inserted onto a formview of an mdi application.when i press File->new option i get a new window with the activex in it. Now i want to implement the same funtionality on a button press. i want the same results as that of File->New.How do i achieve it from the CFormView or the Cmainframe class.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Maybe something like this:

      if (AfxGetApp()->m_pDocManager)
      AfxGetApp()->m_pDocManager->OnFileNew();

      Mark

      Mark Salsbery Microsoft MVP - Visual C++ "Go that way, really fast. If something gets in your way, turn."

      C 1 Reply Last reply
      0
      • M Mark Salsbery

        Maybe something like this:

        if (AfxGetApp()->m_pDocManager)
        AfxGetApp()->m_pDocManager->OnFileNew();

        Mark

        Mark Salsbery Microsoft MVP - Visual C++ "Go that way, really fast. If something gets in your way, turn."

        C Offline
        C Offline
        chaitannya_m
        wrote on last edited by
        #3

        O' My God that really worked like magic.. But how do i get a pointer to each view. I want to pass data to the view

        M 1 Reply Last reply
        0
        • C chaitannya_m

          O' My God that really worked like magic.. But how do i get a pointer to each view. I want to pass data to the view

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          :) I'm glad it worked. That's how MFC does it but it's using an undocumented variable (although it's worked for as long as I can remember). You probably could just give your button the id ID_FILE_NEW and it would have worked like magic too :) I thought for sure someone here would jump on me for that one LOL.

          chaitannya_m wrote:

          But how do i get a pointer to each view. I want to pass data to the view

          Which view? The one just created? The view just created should be the active view. To get the active view in MDI;

          // this is the MFC example from the docs

          CMDIFrameWnd *pFrame =
          (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;

          // Get the active MDI child window.
          CMDIChildWnd *pChild =
          (CMDIChildWnd *) pFrame->GetActiveFrame();

          // or CMDIChildWnd *pChild = pFrame->MDIGetActive();

          // Get the active view attached to the active MDI child
          // window.
          CMyView *pView = (CMyView *) pChild->GetActiveView();

          To iterate through all views, one way is to iterate through all documents and their associated views:

          // Iterate through doc templates

          POSITION DocTemplatePos = AfxGetApp()->GetFirstDocTemplatePosition();
          while (DocTemplatePos != NULL)
          {
          CDocTemplate *pTmpl = AfxGetApp()->GetNextDocTemplate(DocTemplatePos);

          // Iterate through documents for the current template

          POSITION DocPos = pTmpl->GetFirstDocPosition();
          while (DocPos != NULL)
          {
          CDocument *pDoc = pTmpl->GetNextDoc(DocPos);

            **// Iterate through views for the current document**
          
            // You could use CDocument::UpdateAllViews() or ...
          
            POSITION ViewPos = pDoc->GetFirstViewPosition();
            while (ViewPos != NULL)
            {
               CView \*pView = pDoc->GetNextView(ViewPos);
          
               **// Do something with the current view**
            }
          

          }
          }

          Mark Salsbery Microsoft MVP - Visual C++ "Go that way, really fast. If something gets in your way, turn."

          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