Home | Overview | How Do I | Sample | Tutorial
To help put the document/view creation process in perspective, first consider a running program: a document, the frame window used to contain the view, and the view associated with the document.
These relationships are established during document/view creation. The table "Gaining Access to Other Objects in Your Application" below shows how objects in a running program can access other objects. Any object can obtain a pointer to the application object by calling the global function AfxGetApp.
Gaining Access to Other Objects in Your Application
From object | How to access other objects |
Document | Use GetFirstViewPosition and GetNextView to access the document's view list.
Call GetDocTemplate to get the document template. |
View | Call GetDocument to get the document.
Call GetParentFrame to get the frame window. |
Document frame window | Call GetActiveView to get the current view.
Call GetActiveDocument to get the document attached to the current view. |
MDI frame window | Call MDIGetActive to get the currently active CMDIChildWnd. |
Typically, a frame window has one view, but sometimes, as in splitter windows, the same frame window contains multiple views. The frame window keeps a pointer to the currently active view; the pointer is updated any time another view is activated.
Note A pointer to the main frame window is stored in the m_pMainWnd member variable of the application object. A call to OnFileNew in your override of the InitInstance member function of CWinApp sets m_pMainWnd for you. If you don't call OnFileNew, you must set the variable's value in InitInstance yourself. (SDI COM component (server) applications may not set the variable if /Embedding is on the command line.) Note that m_pMainWnd is now a member of class CWinThread rather than CWinApp.