메뉴 바로가기

서브메뉴 바로가기

본문 바로가기

logo

C/C++/MFC

MFC 클래스간 통신

2006.05.25 17:57

WhiteAT 조회 수:12930

 
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 = (CTestDoc *)((CMainFrame *)AfxGetMainWnd())->GetActiveDocument();

4.     View 포인터 얻기
-          CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
           CTestView *pView = (CTestView *)pFrame->GetActiveView();
-          CTestView *pView = (CTestView *) ((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();
            CDsp240Doc *pDoc = (CDsp240Doc *)pChild->GetActiveDocument();
           CDsp240Doc *pDoc = ( CDsp240Doc *)(((CMainFrame *)AfxGetMainWnd())->GetActiveFrame())->GetActiveDocument();

3.     View 포인터 얻기

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

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


 주의 사항
위의 방법으로 포인터를 얻을 때는 해당되는 파일을 include 할때 순서의 주의해야 한다.
#include "MainFrm.h"      // 1. Mainfrm
#include "Dsp240Doc.h"    // 2. Doc
#include "Dsp240View.h"   //  3. View



.

관련 문서가 검색되었습니다.
  1. [2015/03/15] 블루투스로 스텝모터 제어 by WhiteAT (4821)
  2. [2015/03/15] 시리얼 포트로 스텝모터 제어 by WhiteAT (3319)
  3. [2014/11/28] 컴퓨터-아두이노 간의 블루투스 통신 (채팅) by WhiteAT (4807)
  4. [2013/10/30] ZEO-S, CDS로 빛 밝기 -> LED ON/OFF by WhiteAT (8920)
  5. [2013/09/02] ZEO-S PWM 펄스를 Pulse Counter로 읽기, C# by WhiteAT (6785)
  6. [2013/08/29] ZEO-S, Pulse Counter, C# by WhiteAT (6380)
  7. [2013/06/13] ZEO-S, 스위치로 LED ON/OFF, C# by WhiteAT (10121)
  8. [2013/06/08] ZEO-S, LED 연속으로 이동, C# by WhiteAT (8860)
  9. [2013/06/06] ZEO-S, LED 이동 속도 조절, C# by WhiteAT (8749)
  10. [2012/06/06] C#, Form 속에 Form 넣기 (MDI형태) by WhiteAT (26559)