Friday, May 15, 2015

Get pointers in MFC

1) Get CApp in anywhere:
AfxGetApp();

2) Get CDoc in CView:
CYouSDIDoc *pDoc=GetDocument();

3) Get CMainFrame in CApp:
the variable m_pMainWnd in CWinApp
or in anywhere:
CMainFrame *pMain =(CMainFrame *)AfxGetMainWnd();

4) Get CMainFrame in CView:
CMainFrame *pMain=(CMaimFrame *)AfxGetApp()->m_pMainWnd;

5) Get CView:
CMainFrame *pMain=(CmaimFrame *)AfxGetApp()->m_pMainWnd;
CyouView *pView=(CyouView *)pMain->GetActiveView();

6) Get CDoc:
CDocument * pCurrentDoc =(CFrameWnd *)m_pMainWnd->GetActiveDocument();

7) Get CStatusBar and CToolBar:
CStatusBar * pStatusBar=(CStatusBar *)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
CToolBar * pToolBar=(CtoolBar *)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_TOOLBAR);

8) Get Menu in Mainframe:
CMenu *pMenu=m_pMainWnd->GetMenu();

No comments:

Post a Comment