功能:在当前视中有一个按钮,点击它,此视隐藏                  
说明:单文档双视图,视图均基于CFormView                  CMainFrame* pMf=(CMainFrame*)AfxGetMainWnd();
CView* sdi=(CSDIView*)(pMf->m_wndSplitter.GetPane(0,1)); this->ShowWindow(SW_HIDE);
sdi->ShowWindow(SW_SHOW);

                  GetDocument()->RemoveView(this);
pMf->SetActiveView(sdi);
pMf->RecalcLayout();结果:
当前视没有隐藏(分割条仍存在),单不可用,拖动分割条,显视不正常,有谁能帮帮我吗

解决方案 »

  1.   

    单文档分割条多视图时单视图与多视图的切换void CMainFrame::OnViewSplitterwnd() 
    {
    CCreateContext ctx;
    ctx.m_pNewViewClass = RUNTIME_CLASS(CMyView);
    // GetActiveDocument() call before you destroy m_splitter.
    ctx.m_pCurrentDoc = GetActiveDocument();
    ASSERT(ctx.m_pCurrentDoc!=NULL);

    // m_pSplitter !=NULL when there is a visible splitter.
    if (m_pSplitter)
    {
    // Destroy splitter window.
    delete m_pSplitter;
    m_pSplitter = NULL;

    // Create and initialize CMyView.
    SetActiveView((CView*)CreateView(&ctx));
    GetActiveView()->OnInitialUpdate();
    }
    else
    {
    // Destroy CMyView.
    GetActiveView()->DestroyWindow();

    // Create new splitter window.
    m_pSplitter = new CSplitterWnd;
    if (!m_pSplitter->CreateStatic(this, 1, 2))
    {
    TRACE0("Can't create splitter window.\n");
    return;
    }
    else
    {
    if ((!m_pSplitter->CreateView(0, 0,
    RUNTIME_CLASS(CPane1View),
    CSize(350, 0), &ctx))
    ||(!m_pSplitter->CreateView(0, 1,
    RUNTIME_CLASS(CPane2View),
    CSize(0, 0), &ctx)))
    {
    TRACE0("Can't create one of the splitter panes.\n");
    return;
    }

    // Initialize the two panes (each containing a view
    // associated with the current document).
    ((CView*)m_pSplitter->GetPane(0, 0))->OnInitialUpdate();
    ((CView*)m_pSplitter->GetPane(0, 1))->OnInitialUpdate();
    SetActiveView((CView*)m_pSplitter->GetPane(0, 0));
    }
    }

    // Redisplay frame.
    RecalcLayout();
    }
      

  2.   

    建议看一下“深入了解MFC的文档/视图结构”这篇文章。
    百度就能搜到。
      

  3.   

    CSplitterWnd::DeleteView
    virtual void DeleteView( int row, int col );
      

  4.   

    同意,回复人: kongyunzhongque(云雀) ( ) 信誉:118  
    照 他改就可以了。
      

  5.   

    实际上还漏了一些语句,关于文档的一个属性设置;
    文档构造函数:m_bAutoDelete =FALSE;
    主框架关闭时:
    void CMainFrame::OnClose() 
    {
    GetActiveDocument()->m_bAutoDelete = TRUE;

    CFrameWnd::OnClose();
    } 这种替换实际上是已经删除原来的视图了,还有一种重载CSplitterWnd的方法
    http://www.codeproject.com/splitter/st_splitterwnd.asp
      

  6.   

    切分窗口先,先切分,然后才定各个 pane 的内容
    你要重新切分才行啊,切分方式不变,你隐藏也无效当前视没有隐藏(分割条仍存在),单不可用,拖动分割条,显视不正常,有谁能帮帮我吗
    分割条仍存在,它是由切分方式决定出来的。
      

  7.   

    感谢各位的帮助,让此事有了眉目,但有一个新的问题;
    CSplitterWnd m_wndSplitter;
    如此定义分割条,可以正常显示,也可以隐藏,但复原时出错
    CSplitterWnd* m_wndSplitter;
    定义为指针时,调试到下面的****语句时产生异常,运行时提示"该内存不能为读",不知何故,
    郁闷!!!
    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
    {
    // TODO: Add your specialized code here and/or call the base class
    m_wndSplitter->CreateStatic(this,1,2);  //****
    m_wndSplitter->CreateView(0,0,RUNTIME_CLASS(CMyView),CSize(300,0),pContext);
             m_wndSplitter->CreateView(0,1,RUNTIME_CLASS(CSDI1View),CSize(0,0),pContext);
    return TRUE;
    //return CFrameWnd::OnCreateClient(lpcs, pContext);
    }
    还望各位献言献策
      

  8.   

    定义为
    CSplitterWnd* m_wndSplitter;你有没有给它new一下?