在我的一个MDI 程序ReManage中, 定义了几个从CFormView派生的视图:CNoOneParaView,CNoTwoParaView ...;初始化视图为:CNoOneParaView
BOOL CReManageApp::InitInstance() CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_RELAYMTYPE,
RUNTIME_CLASS(CReManageDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CNoOneParaView));//初始化的视图 
AddDocTemplate(pDocTemplate);在程序中,我需要根据用户的菜单选择,来切换视图到CNoTwoParaView。以下是用户下达切换菜单后,我的处理过程:
{
CView* pOldActiveView = this->GetActiveView();
CView* pNewActiveView = (CView*) m_pNoTwoParaView ; if (pNewActiveView)
{
           if (pOldActiveView == pNewActiveView) return; SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pOldActiveView->ShowWindow(SW_HIDE);
pOldActiveView->SetDlgCtrlID(m_nCurrentViewID);
m_nCurrentViewID = 11; RecalcLayout();
}
}

解决方案 »

  1.   

    一个简单的办法:
    CloseAllDocuments(false);               
    pDocTemplate->OpenDocumentFile(NULL);
      

  2.   

    看錯了.SetActiveView放在Recalclayout前面.
      

  3.   

    我試了一下可以的.
    void CMainFrame::OnChgview() 
    {
    CCoolSDIMenuDoc *pDoc=((CCoolSDIMenuView *)GetActiveView())->GetDocument();
        CCoolSDIMenuView *pOldView=(CCoolSDIMenuView *)GetActiveView();
        pDoc->AddView(m_View2) ;
    m_View2->ShowWindow(SW_SHOW);
    pOldView->ShowWindow(SW_HIDE);
    m_View2->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
    pOldView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
        SetActiveView(m_View2);
            pDoc->RemoveView(pOldView);
    RecalcLayout();
    }
    class CMainFrame : public CSpawnFrameWnd
    {public:
        CSecondView *m_View2;
    ....
    }int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    ....
        m_View2=(CSecondView*)RUNTIME_CLASS(CSecondView)->CreateObject();
    m_View2->Create(NULL, NULL, WS_CHILD, 
    CRect(0,0,0,0), this, IDC_VIEW, NULL);
    }
      

  4.   

    pNewActiveView->SetActiveView();
    RecalcLayout();
    Invalidate(TURE);
      

  5.   


    void CMainFrame::OnSwitch() 
    {
    CView *pView = GetRightPane();
    if (pView == NULL)
    return; CRuntimeClass *pViewClass = NULL;
    if (pView->IsKindOf(RUNTIME_CLASS(CViewSwitchView)))
    {
    pViewClass = RUNTIME_CLASS(CRightFormView);
    }
    else if (pView->IsKindOf(RUNTIME_CLASS(CRightFormView)))
    {
    pViewClass = RUNTIME_CLASS(CViewSwitchView);
    }
    CRect rc;
    pView->GetWindowRect(&rc);
    m_wndSplitter.DeleteView(0, 1);
    CCreateContext context;
    context.m_pCurrentDoc = GetActiveDocument();
    context.m_pCurrentFrame = this;
    context.m_pLastView = NULL;
    context.m_pNewDocTemplate = NULL;
    context.m_pNewViewClass = pViewClass;
    if (!m_wndSplitter.CreateView(0,1, pViewClass, rc.Size(), &context))
    ASSERT(FALSE); m_wndSplitter.RecalcLayout();
    }
      

  6.   

    you can use your code in SDI ,but not in MDI ,you must find active doc
      

  7.   

    你可以这样:不断地调用GetNextView()
    CView* pTempView;
    POSITION pos = m_pDoc->GetFirstViewPosition();
    while (pos != NULL)
    {
    pTempView = m_pDoc->GetNextView(pos);
     if(pTempView->IsKindOf(RUNTIME_CLASS(CXXXView)))
    }