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. Getting pointer to MFC Document

Getting pointer to MFC Document

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++graphicsdata-structures
5 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.
  • E Offline
    E Offline
    electronicman_x
    wrote on last edited by
    #1

    I'm currently working with an MDI application and RogueWave's Stingray library. I'm using their SECControlBar class for a dockable window which will contain 2 tree controls selectable by tabs. I have the trees working and the tabs working, but I'm trying to keep all my data in the Document class of my MDI. This SECControlBar class is not doc/view based, it's just a CWnd derivative. My question is how do i get access to my document class via this CWnd derived dockable window? Normally i just use a GetDocument for my view classes to obtain the related document but there is no such function i can see for the same thing from this CWnd derivative. Thanks for you time. Jeff Rothenberg Project Engineer Vector CANtech, Inc.

    M 1 Reply Last reply
    0
    • E electronicman_x

      I'm currently working with an MDI application and RogueWave's Stingray library. I'm using their SECControlBar class for a dockable window which will contain 2 tree controls selectable by tabs. I have the trees working and the tabs working, but I'm trying to keep all my data in the Document class of my MDI. This SECControlBar class is not doc/view based, it's just a CWnd derivative. My question is how do i get access to my document class via this CWnd derived dockable window? Normally i just use a GetDocument for my view classes to obtain the related document but there is no such function i can see for the same thing from this CWnd derivative. Thanks for you time. Jeff Rothenberg Project Engineer Vector CANtech, Inc.

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      Look for GetActiveView ( from CFrameWnd ) call this on the MainFrame ( AfxGetMainWnd ), and with the view, you GetDocument. Max.

      E 1 Reply Last reply
      0
      • M Maximilien

        Look for GetActiveView ( from CFrameWnd ) call this on the MainFrame ( AfxGetMainWnd ), and with the view, you GetDocument. Max.

        E Offline
        E Offline
        electronicman_x
        wrote on last edited by
        #3

        I attempted your suggestion with this code: void ModuleTab::OnModulemenuAddchannel() { // TODO: Add your command handler code here CString display; int work; AfxMessageBox(_T("add channel. later.")); //start CFrameWnd* pMWnd; pMWnd=(CFrameWnd *)AfxGetMainWnd(); CView* pVWnd; pVWnd=pMWnd->GetActiveView(); CGENyDoc* pDoc; pDoc=(CGENyDoc *)pVWnd->GetDocument();//fails debug assertion here. //end work=pDoc->m_myint; work++; pDoc->m_myint=work; display.Format(_T(" value: %d"),work); AfxMessageBox(display); Invalidate(); } It fails where i call get document. It appears that I'm getting the wrong pointer. Any suggestions? Jeff Rothenberg Project Engineer Vector CANtech, Inc.

        M 1 Reply Last reply
        0
        • E electronicman_x

          I attempted your suggestion with this code: void ModuleTab::OnModulemenuAddchannel() { // TODO: Add your command handler code here CString display; int work; AfxMessageBox(_T("add channel. later.")); //start CFrameWnd* pMWnd; pMWnd=(CFrameWnd *)AfxGetMainWnd(); CView* pVWnd; pVWnd=pMWnd->GetActiveView(); CGENyDoc* pDoc; pDoc=(CGENyDoc *)pVWnd->GetDocument();//fails debug assertion here. //end work=pDoc->m_myint; work++; pDoc->m_myint=work; display.Format(_T(" value: %d"),work); AfxMessageBox(display); Invalidate(); } It fails where i call get document. It appears that I'm getting the wrong pointer. Any suggestions? Jeff Rothenberg Project Engineer Vector CANtech, Inc.

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #4

          I'm sorry, I was too fast to answer : The view is inside a frame window. I do this to get the view:

          CMainFrame *pMainFrame = ( CMainFrame* )AfxGetMainWnd();
          ASSERT( pMainFrame );
          CMDIChildWnd *pChild = (CMDIChildWnd *) pMainFrame->GetActiveFrame();
          CView* pView = pChild->GetActiveView();

          Max.

          E 1 Reply Last reply
          0
          • M Maximilien

            I'm sorry, I was too fast to answer : The view is inside a frame window. I do this to get the view:

            CMainFrame *pMainFrame = ( CMainFrame* )AfxGetMainWnd();
            ASSERT( pMainFrame );
            CMDIChildWnd *pChild = (CMDIChildWnd *) pMainFrame->GetActiveFrame();
            CView* pView = pChild->GetActiveView();

            Max.

            E Offline
            E Offline
            electronicman_x
            wrote on last edited by
            #5

            Great!! works good thanks Jeff Rothenberg Project Engineer Vector CANtech, Inc.

            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