Microsoft KB Archive/111814

= How To Get the Current Document in an MDI Application =

Article ID: 111814

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.52 Professional Edition

 Microsoft Visual C++ 1.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q111814

<div class="summary_section">

SUMMARY
To 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.

<div class="moreinformation_section">

MORE INFORMATION
The 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 kbSweptVC600

Keywords: kbhowto kbdocview KB111814

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.