MFC Doc/View: How to obtain a pointer to various objects?
<table border="1" cellpadding="10" cellspacing="0" width="1"><tr><th rowspan="2" align="left" valign="top" nowrap width="83"><font face="Times New Roman" size="3">From this class:</font></th><th colspan="5" align="left" nowrap width="1254"><font face="Times New Roman" size="3">You can access this class using:</font></th></tr><tr><th width="85"><font face="Times New Roman" size="2">CWinApp</font></th><th width="102"><font face="Times New Roman" size="2">CMainFrame</font></th><th width="222"><font face="Times New Roman" size="2">CChildFrame</font></th><th width="432"><font face="Times New Roman" size="2">CDocument</font></th><th width="325"><font face="Times New Roman" size="2">CView</font></th></tr><tr><th align="left" valign="top" nowrap width="83"><font face="Times New Roman" size="2">CWinApp</font></th><td width="85"> </td><td valign="top" nowrap width="102"><font face="Times New Roman"><font size="2" color="#0000ff">AfxGetMainWnd()</font> or<br><font size="2" color="#0000ff">m_pMainWnd</font></font></td><td valign="top" nowrap width="222"><font face="Times New Roman" size="2" color="#0000ff">AfxGetMainWnd()->MDIGetActive()</font></td><td valign="top" nowrap width="432"><font face="Times New Roman" size="2" color="#0000ff">AfxGetMainWnd()->GetActiveView()->GetDocument()</font></td><td valign="top" nowrap width="325"><font face="Times New Roman" size="2" color="#0000ff">AfxGetMainWnd()->GetActiveView()</font></td></tr><tr><th align="left" valign="top" nowrap width="83"><font face="Times New Roman" size="2">CMainFrame</font></th><td valign="top" nowrap width="85"><font face="Times New Roman"><font size="2" color="#0000ff">AfxGetApp()</font> or<br><font size="2" color="#0000ff">theApp</font></font></td><td width="102"> </td><td valign="top" nowrap width="222"><font face="Times New Roman"><font size="2" color="#0000ff">MDIGetActive()</font> or<br><font face="Arial, Helvetica" size="2" color="#0000ff">GetActiveFrame()</font></font></td><td valign="top" nowrap width="432"><font face="Times New Roman">SDI: <font face="Arial, Helvetica" size="2" color="#0000ff">GetActiveView()->GetDocument()</font><br>MDI: <font face="Arial, Helvetica" size="2" color="#0000ff">MDIGetActive()->GetActiveView()->GetDocument()</font></font></td><td valign="top" nowrap width="325"><font face="Times New Roman">SDI: <font face="Arial, Helvetica" size="2" color="#0000ff">GetActiveView()</font><br>MDI: <font face="Arial, Helvetica" size="2" color="#0000ff">MDIGetActive()->GetActiveView()</font></font></td></tr><tr><th align="left" valign="top" nowrap width="83"><font face="Times New Roman" size="2">CChildFrame</font></th><td valign="top" nowrap width="85"><font face="Times New Roman"><font size="2" color="#0000ff">AfxGetApp()</font> or<br><font size="2" color="#0000ff">theApp</font></font></td><td valign="top" nowrap width="102"><font face="Times New Roman" size="2" color="#0000ff">GetParentFrame()</font></td><td width="222"> </td><td valign="top" nowrap width="432"><font face="Times New Roman" size="2" color="#0000ff">GetActiveView()->GetDocument()</font></td><td valign="top" nowrap width="325"><font face="Times New Roman" size="2" color="#0000ff">GetActiveView()</font></td></tr><tr><th align="left" valign="top" nowrap width="83"><font face="Times New Roman" size="2">CDocument</font></th><td valign="top" nowrap width="85"><font face="Times New Roman"><font size="2" color="#0000ff">AfxGetApp()</font> or<br><font size="2" color="#0000ff">theApp</font></font></td><td valign="top" nowrap width="102"><font face="Times New Roman" size="2" color="#0000ff">AfxGetMainWnd()</font></td><td valign="top" nowrap width="222"><font face="Times New Roman" size="2" color="#0000ff">AfxGetMainWnd()->MDIGetActive()</font></td><td width="432"> </td><td valign="top" nowrap width="325"><font face="Times New Roman"><font size="2" color="#0000ff">POSITION pos =GetFirstViewPosition();<br>GetNextView(pos);</font><br>(see note below)</font></td></tr><tr><th align="left" valign="top" nowrap width="83"><font face="Times New Roman" size="2">CView</font></th><td valign="top" nowrap width="85"><font face="Times New Roman"><font size="2" color="#0000ff">AfxGetApp()</font> or<br><font size="2" color="#0000ff">theApp</font></font></td><td valign="top" nowrap width="102"><font face="Times New Roman" size="2" color="#0000ff">AfxGetMainWnd()</font></td><td valign="top" nowrap width="222"><font face="Times New Roman" size="2" color="#0000ff">GetParentFrame()</font></td><td valign="top" nowrap width="432"><font face="Times New Roman" size="2" color="#0000ff">GetDocument()</font></td><td width="325"> </td></tr><tr><th rowspan="2" align="left" valign="top" nowrap width="83"><font face="Times New Roman" size="2">any other class</font></th><td valign="top" nowrap width="85"><font face="Times New Roman" size="2" color="#0000ff">AfxGetApp()</font></td><td valign="top" nowrap width="102"><font face="Times New Roman" size="2" color="#0000ff">AfxGetMainWnd()</font></td><td valign="top" nowrap width="222"><font face="Times New Roman"><font size="2" color="#0000ff">AfxGetMainWnd()->MDIGetActive()</font> or<br><font face="Arial, Helvetica" size="2" color="#0000ff">AfxGetMainWnd()->GetActiveFrame()</font></font></td><td valign="top" nowrap width="432"><font face="Times New Roman">SDI: <font face="Arial, Helvetica" size="2" color="#0000ff">AfxGetMainWnd()->GetActiveView()->GetDocument()</font><br>MDI: <font face="Arial, Helvetica" size="2" color="#0000ff">AfxGetMainWnd()->MDIGetActive()->GetActiveView()->GetDocument()</font></font></td><td valign="top" nowrap width="325"><font face="Times New Roman">SDI: <font face="Arial, Helvetica" size="2" color="#0000ff">AfxGetMainWnd()->GetActiveView()</font><br>MDI: <font face="Arial, Helvetica" size="2" color="#0000ff">AfxGetMainWnd()->MDIGetActive()->GetActiveView()</font></font></td></tr><tr><td colspan="5" width="1254"><font face="Times New Roman"><b>Note:</b> To access only the current view, the document class can call <font face="Arial, Helvetica" size="2" color="#0000ff">AfxGetMainWnd()->GetActiveView()</font> from a SDI application or <font face="Arial, Helvetica" size="2" color="#0000ff">AfxGetMainWnd()->MDIGetActive()->GetActiveView()</font> from a MDI application.</font></td></tr></table><br><br>