Document/View relationships:
1. A document keeps a list of the views of that document and a pointer to the document template that created the document.
2. A view keeps a pointer to its document and is a child of its parent frame window.
3. A document frame window keeps a pointer to its current active view.
4. A document template keeps a list of its open documents.
5. The application keeps a list of its document templates.
These relationships are established during document/view creation. The table "Gaining Windows OS keeps track of all open windows so it can send messages to them.
***Any object can obtain a pointer to the application object by calling the global function AfxGetApp.
Here are the ways to navigate and access the Document/View objects:
-From CDocument call GetFirstViewPosition and GetNextView to access the document's view list because a Document could have many views. Call GetDocTemplate to get the document template.
-From CView call GetDocument to get the document and call GetParentFrame to get the frame window of this view.
-From CFrameWnd call GetActiveView to get the current view and call GetActiveDocument to get the document attached to the current view.
-From CMDIFrameWnd frame window call MDIGetActive to get the currently active CMDIChildWnd.
Also there are Afx* global functions AfxGetApp(), AfxGetMainWnd() ...
It is understood that you derive your proper classes from each above classes:
CDocument, Cview, CFrameWnd, CMDIFrameWnd, CMDIChildWnd
CWinApp* pApp = ::AfxGetApp();
CMDIFrameWnd *pFrame =(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMainFrame : public CMDIFrameWnd
{
}
CMainFrame * pMainFrame = (CMainFrame*)AfxGetMainWnd();
-obislavu-