我在CChildFrame中分割成两个视图
现在我的一个视图要调用Mainfrm中的成员,
如何得到CMainFrame的指针。

解决方案 »

  1.   

    在View中获得MainFrame指针 CMainFrame *pMain=(CmaimFrame *)AfxGetApp()->m_pMainWnd;
      

  2.   

    CMainFrame *pMainFrame = (CMainFrame *)AfxGetMainFrame();
      

  3.   

    这两种我都用过了,执行第一句就是弹出异常错误。
    CMainFrame *pMain=(CMainFrame *)AfxGetApp()->m_pMainWnd;
    pMain->m_wndStatusBar.SetPaneText( 0, "START RETRIEVING PACKETS...", TRUE );我在CMainFrame 中还新建了个子窗体,代码是这样的。
    void CMainFrame::OnNewDetail() 
    {
    // TODO: Add your command handler code here
    CMDIChildWnd* pActiveChild=MDIGetActive();
    CDocument* pDocument;
    if(pActiveChild==NULL || (pDocument=pActiveChild->GetActiveDocument())==NULL)
    {
    TRACE("Warning:No active document for WindowNew command\n");
    AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
    return;
    }
    CDocTemplate* pTemplate=((CGetPacketApp*)AfxGetApp())->m_pTemplateDetail;
    ASSERT_VALID(pTemplate);
    CFrameWnd* pFrame=pTemplate->CreateNewFrame(pDocument,pActiveChild);
    if(pFrame==NULL)
    {
    TRACE("Warning:failed to create new frame\n");
    AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
    return;
    }
    pTemplate->InitialUpdateFrame(pFrame,pDocument);
    }
    同样我在app文件中加了个模板。
    m_pTemplateDetail= new CMultiDocTemplate(
    IDR_MAINFRAME,
    RUNTIME_CLASS(CGetPacketDoc),
    RUNTIME_CLASS(CDetalChildFram), // custom MDI child frame
    RUNTIME_CLASS(CDetailView));会不会跟这个有关?
      

  4.   

    #include "mainfrm.h" 加了么
      

  5.   

    都没有用啊我用sdi都行,到了mdi就不行了,真实奇怪
      

  6.   

    还有一种方法:
    #include "mainfrm.h" 
    extern  ?????App theApp;CMainFrame* pMainFrm=(CMainFrame*)theApp.m_pMainWnd;
      

  7.   

    (CMainFrame*)(::AfxGetApp())->GetMainWnd();
      

  8.   

    pMain->m_wndStatusBar是私有成员,把它移到piblic下面
      

  9.   

    调试,CMainFrame *pMain=(CMainFrame *)AfxGetApp()->m_pMainWnd;这句话执行都有问题吗