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