AfxGetMainWnd

If your application is an OLE server, call this function to retrieve a pointer to the active main window of the application instead of directly referring to the m_pMainWnd member of the application object.

CWnd* AFXAPI AfxGetMainWnd( );

Return Value

If the server has an object that is in-place active inside a container, and this container is active, this function returns a pointer to the frame window object that contains the in-place active document.

If there is no object that is in-place active within a container, or your application is not an OLE server, this function simply returns the m_pMainWnd of your application object.

If AfxGetMainWnd is called from the application's primary thread, it returns the application's main window according to the above rules. If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call.

Remarks

If your application is not an OLE server, then calling this function is equivalent to directly referring to the m_pMainWnd member of your application object.

Example

//The following line send a WM_CLOSE message  
//   to the Application's main window. This will cause the 
//   Application to exit.
AfxGetMainWnd()->PostMessage(WM_CLOSE, 0, 0);

Requirements

Header: afxwin.h

See Also

Reference

CWinThread::m_pMainWnd

Concepts

MFC Macros and Globals