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


    文章标题:动态切换视图窗口
    原 作 者:程红秀
    原 出 处: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 file op
    python write read
    Linux MD RAID 10
    bitmap.h
    1
    write 1 to block device
    tr '00' '377' < /dev/zero | dd of=/dev/$i bs=1024 count=1024000
    Superblock
    echo -e "33[41;36m something here 33[0m"
    May It Be
  • 原文地址:https://www.cnblogs.com/seacode/p/1757468.html
Copyright © 2020-2023  润新知