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

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

MFC Doc/View: How to obtain a pointer to various objects?
From this class: You can access this class using:
CWinApp CMainFrame CChildFrame CDocument CView
CWinApp AfxGetMainWnd() or
m_pMainWnd AfxGetMainWnd()->MDIGetActive() AfxGetMainWnd()->GetActiveView()->GetDocument() AfxGetMainWnd()->GetActiveView()
CMainFrame AfxGetApp() or
theApp MDIGetActive() or
GetActiveFrame() SDI: GetActiveView()->GetDocument()
MDI: MDIGetActive()->GetActiveView()->GetDocument() SDI: GetActiveView()
MDI: MDIGetActive()->GetActiveView()
CChildFrame AfxGetApp() or
theApp GetParentFrame() GetActiveView()->GetDocument() GetActiveView()
CDocument AfxGetApp() or
theApp AfxGetMainWnd() AfxGetMainWnd()->MDIGetActive() POSITION pos =GetFirstViewPosition();
(see note below)
CView AfxGetApp() or
theApp AfxGetMainWnd() GetParentFrame() GetDocument()
any other class AfxGetApp() AfxGetMainWnd() AfxGetMainWnd()->MDIGetActive() or
AfxGetMainWnd()->GetActiveFrame() SDI: AfxGetMainWnd()->GetActiveView()->GetDocument()
MDI: AfxGetMainWnd()->MDIGetActive()->GetActiveView()->GetDocument() SDI: AfxGetMainWnd()->GetActiveView()
MDI: AfxGetMainWnd()->MDIGetActive()->GetActiveView()
Note: To access only the current view, the document class can call AfxGetMainWnd()->GetActiveView() from a SDI application or AfxGetMainWnd()->MDIGetActive()->GetActiveView() from a MDI application.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s