Where The Streets Have No Name

MFC 클래스간 통신 본문

Developement/C, C++, C#

MFC 클래스간 통신

highheat 2008. 5. 10. 20:25
출처 : http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=51&MAEULNO=20&no=7362&page=23


클래스간 통신입니다. 저는 문서로 만들어놓고 자주 참고 하여 개발하고 있습니다.
의외로 자주 사용하게 되더라고요.. 좋은 자료 되었으면 합니다.

MFC 클래스간 통신


SDI 형태


1.     MainFrame 얻기


-          CMainFrame *pFrame = (CmainFrame *) AfxGetMainWnd();


2.     App 포인터 얻기


-          CTestApp *pApp = (CtestApp *) AfxGetApp();


3.     Document 포인터 얻기


-          CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
            CTestDoc *pDoc = (CTestDoc *)pFrame->GetActiveDocument();


-           CTestDoc *pDoc = ((CMainFrame *)AfxGetMainWnd())->GetActiveDocument();


4.     View 포인터 얻기


-          CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
            CTestView *pView = (CTestView *)pFrame->GetActiveView();


-           CTestView *pView = ((CMainFrame *)AfxGetMainWnd())->GetActiveView();


MDI 형태


1.     ChildFrame 포인터 얻기


-          CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
            CChildFrame *pChild = (CChildFrame *)pFrame->GetActiveFrame();


-          CChildFrame *pChild = ((CMainFrame *)AfxGetMainWnd())->GetActiveFrame();


2.     Document 포인터 얻기


-          CMainFrame *pFrame = (CMainFrame)AfxGetMainWnd();
            CChildFrame *pChild = (CChildFrame *)pFrame->GetActiveFrame();
            CMdiTestDoc *pDoc = (CMdiTestDoc *)pChild->GetActiveDocument();


-          CMdiTestDoc *pDoc = (((CMainFrame *)AfxGetMainWnd())->GetActiveFrame())->GetActiveDocument();


3.     View 포인터 얻기


-          CCainFrame *pFrame = (CMainFrame)AfxGetMainWnd();
            CChildFrame *pChild = (CChildFrame *)pFrame->GetActiveFrame();
            CMdiTestView *pView = (CMdiTestDoc *)pChild->GetActiveView();


-          CMdiTestView *pView = (((CMainFrame *)AfxGetMainWnd())->GetActiveFrame())->GetActiveView();