« Using MFC: The Doc/View Print LoopParameter Reflection and Serialization »

MFC: Doc/View & GetActiveDocument

One particularly unnerving thing in the MFC Document / View implementation is the fact that CMDIFrameWnd::GetActiveDocument() function does return NULL, since it is not the window actually holding the document. You should use a function like the following one to get the document in the MDIFrameWnd:
CDocument* CMyFrame::GetActiveDocumentForSure()
{
    // Get the active MDI child window. 
    CMDIChildWnd *child = MDIGetActive();
    if (!child) return 0;
    // Get the active view 
    CView *view = (CView *) child->GetActiveView();
    if (!view) return 0;
    // get the document from the view
    return view->GetDocument();
}
by axel
2005-07-27. 18:04:51. 82 words, 5678 views. Categories: programming, C++, MFC , Leave a comment »Send a trackback »

Trackback address for this post

Trackback URL (right click and copy shortcut/link location)

Feedback awaiting moderation

This post has 1483 feedbacks awaiting moderation...

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)