• 动态切换视图窗口(转)


    文章标题:动态切换视图窗口
    原 作 者:程红秀
    原 出 处:vczx.com
    发 布 者:chx20
    发布类型:原创
    发布日期:2005-12-12
    今日/总浏览:1/4972
    下载代码:

    在CMainFrame中定义变量:

    CSplitterWnd m_wndSplitter;

    BOOL CMainFrame::ReplaceView(int row, int col, CRuntimeClass *pViewClass, SIZE
        size
    )
    {
       
    CCreateContext context;
       
    BOOL bSetActive;

       
    if ((this->m_wndSplitter.GetPane(row, col)->IsKindOf(pViewClass)) == TRUE)
           
    return FALSE;

       
    //获取文档对象的指针,以便在创建新视图的过程中能够使用它
       
    CDocument *pDoc = ((CView*)m_wndSplitter.GetPane(row, col))->GetDocument();

       
    CView *pActiveView = this->GetActiveView();
       
    if (pActiveView == NULL || pActiveView == m_wndSplitter.GetPane(row, col))
           
    bSetActive = TRUE;
       
    else
           
    bSetActive = FALSE;

       
    pDoc->m_bAutoDelete = FALSE; //设置标志,这样当视图销毁时不会删除文档
       
    ((CView*)m_wndSplitter.GetPane(row, col))->DestroyWindow(); //删除存在的视图
       
    pDoc->m_bAutoDelete = TRUE; //设回默认的标志


        //创建新视图
       
    context.m_pNewViewClass = pViewClass;
       
    context.m_pCurrentDoc = pDoc;
       
    context.m_pNewDocTemplate = NULL;
       
    context.m_pLastView = NULL;
       
    context.m_pCurrentFrame = NULL;
       
    m_wndSplitter.CreateView(row, col, pViewClass, size, &context);


       
    CView *pNewView = (CView*)m_wndSplitter.GetPane(row, col);

       
    if (bSetActive == TRUE)
           
    this->SetActiveView(pNewView);

       
    m_wndSplitter.RecalcLayout(); //重新计算位置
        // m_wndSplitter.GetPane(row,col)->SendMessage(WM_PAINT);

       
    return TRUE;
    }

    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext *pContext)
    {
       
    if (!m_wndSplitter.CreateStatic(this, 1, 2))
           
    return FALSE;

       
    if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CTView), CSize(200, 100),
           
    pContext))
           
    return FALSE;

       
    if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CFView), CSize(100, 100),
           
    pContext))
           
    return FALSE;

       
    m_bFormView = true;
       
    return TRUE;
    }


    void CMainFrame::OnFormView()
    {
       
    ReplaceView(0, 1, RUNTIME_CLASS(CFView), CSize(100, 100));
       
    m_bFormView = true;
    }

    void CMainFrame::OnListView()
    {
       
    ReplaceView(0, 1, RUNTIME_CLASS(CVVView), CSize(100, 100));
       
    m_bFormView = false;

    }

    void CMainFrame::OnUpdateFormView(CCmdUI *pCmdUI)
    {
       
    pCmdUI->SetCheck(m_bFormView);
    }

    void CMainFrame::OnUpdateListView(CCmdUI *pCmdUI)
    {
       
    pCmdUI->SetCheck(!m_bFormView);
    }

  • 相关阅读:
    python
    图片放大,缩小等操作
    template-web.js 自定义过滤器
    python
    python
    Android Volley源码分析及扩展
    Android 6.0动态权限申请教程
    Jarsigner签名使用
    Python正则表达式(总)
    Python错误和异常概念(总)
  • 原文地址:https://www.cnblogs.com/seacode/p/1757468.html
Copyright © 2020-2023  润新知