我只知道在View 中调用CMainFrame 的方法:
CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;但是现在反过来如何实现阿????

解决方案 »

  1.   

    CYourView //你的视图类。
    (CYourView*)GetActiveView()->成员变量。
      

  2.   

    可用nanjianhui(nan)的方法,但此方法有局限。
    最安全的方法是:
    CFrameWnd * pFrameWnd=(CFrameWnd*)AfxGetMainWnd();
    CView* pView=pFrameWnd->GetActiveFrame()->GetActiveView();
    ...pView->成员变量...;
      

  3.   

    我已经试过了,因为我的是formview ,所以不行。有别的办法吗?
      

  4.   

    呵呵,刚好我想知道View 中调用CMainFrame 的方法,谢谢了!
    可惜反过来调用我也不知道:(
      

  5.   

    CFrameWnd * pFrameWnd=(CFrameWnd*)AfxGetMainWnd();
    CView* pView=pFrameWnd->GetActiveFrame()->GetActiveView();
      

  6.   

    说明:
    CMyFormView:public CFormView
    {};
    在FormView放了一个Edit(IDC_TEST_EDIT)控件,在程序中设置Edit中显示的字符串为:“This is the testing string!”
    具体的步骤为:
    添加菜单:
    Test
    Aceess FormView From CMainFrame
    //like the following:
    IDR_MAINFRAME MENU 
        POPUP "Test"
        BEGIN
            MENUITEM "Aceess FormView From CMainFrame", ID_ACCESS_FORMVIEW
        END
        ----------------------------------------------------------
    //file:MainFrm.cpp
    ....
    #include "MainFrm.h"
    #include "FormDoc.h"
    #include "FormView.h"
    ....
    void CMainFrame::OnAccessFormview() 
    {
    //在MainFrame中访问FormView中的变量
    // TODO: Add your command handler code here
    CMyFormView *pFormView=(CMyFormView*)this->GetActiveView();
    CEdit *pEdit=(CEdit*)pFormView->GetDlgItem(IDC_TEST_EDIT);
    pEdit->SetWindowText("This is the testing string!");
    }