先把我的代码贴上
void CMainFrame::OnChangeView(WPARAM wParam)
{
int nIndex=(int)wParam; CCreateContext contextT;
CView* pOldView = (CView*)m_swSplitterWnd.GetActivePane();
contextT.m_pLastView = pOldView;
contextT.m_pCurrentDoc = pOldView->GetDocument();
contextT.m_pNewDocTemplate =contextT.m_pCurrentDoc->GetDocTemplate();
m_swSplitterWnd.DeleteView(0,1);
    switch(nIndex)
{
case 1:
m_swSplitterWnd.CreateView(0,1,RUNTIME_CLASS(CExamScanView),CSize(150,200),&contextT);
break;
case 2:
m_swSplitterWnd.CreateView(0,1,RUNTIME_CLASS(CSetPointView),CSize(150,200),&contextT);
break;
case 3:
m_swSplitterWnd.CreateView(0,1,RUNTIME_CLASS(CSetAnswerView),CSize(150,200),&contextT);
break;
case 4:
m_swSplitterWnd.CreateView(0,1,RUNTIME_CLASS(CScanStepView),CSize(150,200),&contextT);
break;
case 5:
m_swSplitterWnd.CreateView(0,1,RUNTIME_CLASS(CErrorModifyView),CSize(150,200),&contextT);
break;
case 6:
break; }

    m_swSplitterWnd.RecalcLayout();
    }
OnChangeView是自定义的消息函数,当在视图上单击某按钮时发送给主框架这个消息,并传递一个参数指明要切换到哪个视图,以上代码在DEBUG下运行正常,在RELEASE下异常退出,哪位高手指点一下啊?

解决方案 »

  1.   

    LZ明确是这个函数出错吗?
    建议将Release中添加debug信息,确定出错的地方,同时添加日志文件来跟踪。
    还有就是你的代码中没有对指针进行NULL的检查。
      

  2.   

    ZeroMemory(&contextT, sizeof(CCreateContext));
      

  3.   

    唉,指针检查了, 结构内存也初始化了~~但没用,跟踪进去后定位到一个汇编语句
    CALL  77D194A4
    NND这是中断么??
    汇编不熟啊,头疼~~~
      

  4.   

    你这样是每次都创建新视图,删除原来视图,不好
    一般是每个视图只创建一次,把指针保存起来
    创建前先检查对应指针,如果不为NULL,就不再创建,使用原来创建的视图
    切换视图时先显示新视图,再隐藏老视图,RecalcLayout
    参考我的:
    void CSubFrame::SwitchToView(UINT nView)
    {
    if(nView == m_nCurView)
    return; CView* pOldActiveView = GetActiveView();
    CView* pNewActiveView = (CView*) GetDlgItem(nView);

    if (pNewActiveView == NULL) 
    {
    TRACE1("dynamic create view: %d\n", nView);
    switch (nView)
    {
    case ID_FORM_SETTING:
    pNewActiveView = m_pSettingForm = new CSettingForm;
    break; case ID_FORM_MATERIAL:
    pNewActiveView = m_pMaterialForm = new CMaterialForm;
    break; default:
    ASSERT(FALSE);
    }        CCreateContext context;
            context.m_pCurrentDoc = pOldActiveView->GetDocument();        pNewActiveView->Create(NULL, NULL, 0L, //WS_BORDER
    CFrameWnd::rectDefault, this, nView, &context);        // call OnInitialUpdate explicitly
            pNewActiveView->OnInitialUpdate();
        }
    if (pNewActiveView)
    {
    // don't switch when views are the same
    if (pOldActiveView != pNewActiveView)
    {
    SetActiveView(pNewActiveView);
    pNewActiveView->ShowWindow(SW_SHOW);
    pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST); ASSERT_VALID(pOldActiveView);
    pOldActiveView->ShowWindow(SW_HIDE);
    pOldActiveView->SetDlgCtrlID(m_nCurView);

    m_nCurView = nView;
    }
    RecalcLayout();
    }
    }
      

  5.   

    pNewActiveView->Create(NULL, NULL, 0L, //WS_BORDER
    CFrameWnd::rectDefault, this, nView, &context);这里面吗??
      

  6.   

    http://www.codeproject.com/docview/dynviews.asp