Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

any doc or view to get a pointer to the app that owns them.

CPopApp* papp = (CPopApp*)(::AfxGetApp()); cast C!inApp*


"ew to get a pointer to its #owner$ doc.
CPop%oc* pdoc = Get%oc&ment();

way for a doc&ment to 'now which of its views( if any( is the active foc&s window of the &ser interface
CPopDoc::getActiveView()

You can access this class using: From this class: CWin App CMain Frame CChildFrame CDocument CView

CWinApp

AfxGet MainW nd() or m_pMa inWnd AfxG etApp () or theAp p AfxG etApp () or theAp p AfxG etApp () or theAp p AfxG etApp () or theAp p AfxG etApp ()

AfxGetMainWnd()>MDIGetActive()

AfxGetMainWnd()->GetActiveView()>GetDocument()

AfxGetMainWnd()->GetActiveView()

CMainFrame

MDIGetActive() or GetActiveFrame()

DI! GetActiveView()->GetDocument() MDI! MDIGetActive()->GetActiveView()-

>GetDocument()

DI! GetActiveView() MDI! MDIGetActive()->GetActiveView()

CChildFrame

Get"are ntFrame ()

GetActiveView()->GetDocument()

GetActiveView()

CDocument

AfxGet MainW nd()

AfxGetMainWnd()>MDIGetActive()

"# I$I#% po& 'GetFir&tView"o&ition()( Get%extView(po&)( (&ee note )e*ow)

CView

AfxGet MainW nd()

Get"arentFrame()

GetDocument()

any other class

AfxGet MainW nd()

AfxGetMainWnd()>MDIGetActive() or AfxGetMainWnd()>GetActiveFrame()

DI! AfxGetMainWnd()->GetActiveView()-

>GetDocument() MDI! AfxGetMainWnd()->MDIGetActive()>GetActiveView()->GetDocument()

DI! AfxGetMainWnd()->GetActiveView() MDI! AfxGetMainWnd()->MDIGetActive()-

>GetActiveView()

Note: $o acce&& on*+ the current view, the document c*a&& can ca** AfxGetMainWnd()->GetActiveView() from a DI app*ication or AfxGetMainWnd()->MDIGetActive()->GetActiveView() from a MDI app*ication-

MFC Doc/View: How to obtain a pointer to various objects?

You might also like