一个继承CFormView的CMyFormView,如何将它加载到对话框上??

解决方案 »

  1.   

    下面这段代码可以在对话框上添加任何视图:
    void CxxxDlg::AddObjectView(CRuntimeClass *pViewClass)
    {
    CCreateContext pContext;
    CWnd* pFrameWnd = this;
      
    pContext.m_pCurrentDoc = new CxxxDoc;
    pContext.m_pNewViewClass = pViewClass;
    CView *pView =
    (CView*)((CFrameWnd*)pFrameWnd)->CreateView(&pContext);
    ASSERT(pView);
    pView->ShowWindow(SW_NORMAL);
    m_pView = pView;
    }
    不过在release版本中还要注意一些问题
      

  2.   

    在对话框类里加一个 CYourFormView  类型的公有指变量m_pView
    OnInitDialog()里
     m_pView = new CYourFormView;
    m_pView->Create(.........
    m_pView->ShowWindow(...
      

  3.   

    直接把对话框改成formview是否更好呢?
      

  4.   

    抛出什么异常了?debug or release 模式?
      

  5.   

    debug模式,现象为当鼠标单击激活视图时抛出异常,要不我把源程序给您看一下?
      

  6.   

    在你的视图中添加一下代码:
    在.h文件中添加声明
    #ifdef _DEBUG
    afx_msg int OnMouseActivate(CWnd*, UINT, UINT);
    #endif在.cpp文件中添加实现
    #ifdef _DEBUG
    int CYOurView::OnMouseActivate(CWnd*, UINT, UINT)
    {
    return MA_ACTIVATE;
    }
    #endif