HOWTO: Get the Current Document in an MDI ApplicationLast reviewed: May 28, 1997Article ID: Q111814 |
The information in this article applies to:
SUMMARYTo get a pointer to the currently active document from an MDI application, use the CMDIFrameWnd::MDIGetActive() function. MDIGetActive() returns a pointer to the active CMDIChildWnd. This CMDIChildWnd * enables you to get a valid pointer to the currently active document via GetActiveDocument(). See the online help and "Class Libraries Reference" for more information about these functions.
MORE INFORMATIONThe sample below shows how to get a valid pointer to the currently active document anywhere within an MDI application.
Sample Code
/* Compile options needed: */ void Some_Function() { CMyDoc *pActiveDoc; // CMyDoc derived from CDocument CMyFrame *pActiveFrame; // CMyFrame derived from CMDIChildWnd pActiveFrame =(CMyFrame*) ((CMainFrame*)(AfxGetApp()->m_pMainWnd))->MDIGetActive(); // MFC 2.5 and later versions contain AfxGetMainWnd(), which // can be used to gain access to the main window instead of // "AfxGetApp()->m_pMainWnd pActiveDoc = (CMyDoc*)pActiveFrame->GetActiveDocument(); } |
Additional query words: MFC CDocument
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |