본문 바로가기
IT창고/MFC

MFC 클래스에서 포인터 얻기

by 창구창고 2008. 3. 5.

📑 목차

    반응형

    1. App 클래스의 포인터를 얻을 때                // 어디서든 연결가능 (view doc frm...)

     AfxGetApp();

    // CChoonApp *pApp = (CChoonApp *)AfxGetApp()          // 클래스명 Choon


    2. 메인 프레임 클래스의 포인터를 얻을 때     (app와 같이 어디서든..)

     AfxGetMainWnd();

    //  CMainFrame *pFrm = AfxGetApp()->m_pMainWnd;

    //  (CMainFrame *)AfxGetMainWnd()

    // CMainFrame *pFrm = (CMainFram *)AfxGetMainWnd();



    3 메인프레임에서 뷰 얻을 때 (Frm -> view)
     GetActiveView

    // CChoonView *pView = pFrm->GetActiveView;


    4. 메인프레임 도큐먼트 얻을때 (Frm -> Doc)
     GetDocument();

    // CChoonDoc *pDoc = pView->GetDocument();


    5. 뷰에서 메인프레임 얻을때 (View -> Frm)

     GetParentFrame()

    // CFrameWnd *GetParentFrame() const  (사용법 이상함)
    // CMainFrame *pFrm = (CMainFrame *)GetParentFrame(); //const


    6. 뷰에서 도큐먼트 얻을때 (View -> Doc)
     GetDocument()
    // CChoonDoc *pDoc = GetDocument();

    7. 도큐먼트에서 뷰 얻을때 (Doc -> View)

    GetFirstViewPosition();


    여러개의 경우
    POSITION pos = GetFirstViewPosition();

    while(pos !=Null)
    {
     CChoonView *pView = GetNextNew(pos);
     pView->UpdateWindow();
    }
     

    GetNextView();
    오직 한개
    void CChoonDoc::OnRepaintViews()
    {
     CView *pView = m_viewList.GetHead();
     pView->UpdateWindows();
    }



    ○ 루트를 통해서 연결하는 예제
    // CMainFrame *pFrm = (CMainFrame *)AfxGetMainWnd();
       CRefenceDoc *pDoc = (CRefenceDoc *)pFrm->GetActiveDocument();

    한줄로한것 CRefenceDoc *pDoc = (CRefenceDoc *)((CMainFrame *)AfxGetMainWnd())->GetActiveDocument();
     

    ○ 임의의 클래스에서 뷰로 연결 -> view
    1. CChoonView *pView = (CChoonView *)((CMainWnd *)AfxGetMainWnd())-> GetActiveView();
    --> 임의의 클래스에서 AfxGetMainWnd로 frm을 거쳐서 GetActiveView로해서 view로

    반응형

    "이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다."