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. Get pointer to document in a SDI from everywhere?

Get pointer to document in a SDI from everywhere?

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 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.
  • L Offline
    L Offline
    loic
    wrote on last edited by
    #1

    Hi all, It looks like a simple question, but I can't find a clean answer. How is it possible to get in the cleanest way as possible a pointer to the active document (as it is a SDI, only one!) from everywhere, especially from the class associated to a dialog (CDialog). Thank you, loic

    M 1 Reply Last reply
    0
    • L loic

      Hi all, It looks like a simple question, but I can't find a clean answer. How is it possible to get in the cleanest way as possible a pointer to the active document (as it is a SDI, only one!) from everywhere, especially from the class associated to a dialog (CDialog). Thank you, loic

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

      Uhm... would this be of any help? CYourApp* theApp; theApp = (CYourApp*)AfxGetApp(); CYourView* pView = (CYourView*) ((CFrameWnd*) theApp->m_pMainWnd)->GetActiveView(); CYourDoc* pDoc = pView->GetDocument(); First get a pointer to the application, then with that a pointer to the active view, and through the view pointer to the document. Or did you say the cleanest possible way? ;) ------------------------------------------ Experience is the name every one gives to their mistakes. -- Oscar Wilde Experience is one thing you can't get for nothing. -- Oscar Wilde

      L 1 Reply Last reply
      0
      • M MVH

        Uhm... would this be of any help? CYourApp* theApp; theApp = (CYourApp*)AfxGetApp(); CYourView* pView = (CYourView*) ((CFrameWnd*) theApp->m_pMainWnd)->GetActiveView(); CYourDoc* pDoc = pView->GetDocument(); First get a pointer to the application, then with that a pointer to the active view, and through the view pointer to the document. Or did you say the cleanest possible way? ;) ------------------------------------------ Experience is the name every one gives to their mistakes. -- Oscar Wilde Experience is one thing you can't get for nothing. -- Oscar Wilde

        L Offline
        L Offline
        loic
        wrote on last edited by
        #3

        :) In fact, if you take your code and put it in a new app, this is not fun... I keep this reciep for next time, but here I found the way to do that. I just store a pointer to the document in a member var of my dialog class at creation time in CMainFrame or whatever, so I can directly access it after. Thank you for your answer, it gives me also the links from theApp to pDoc... :) loic

        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