如何在不使用 CSplitterWnd::Create 的情况下在 MFC 中动态拆分窗口 [英] How to split a Window dynamically in MFC without using CSplitterWnd::Create

查看:48
本文介绍了如何在不使用 CSplitterWnd::Create 的情况下在 MFC 中动态拆分窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 MFC MDI 应用程序,并希望通过右键单击并选择AddSplitWnd"弹出菜单项,一次将窗口动态拆分为两部分.我尝试使用 CSplitterWnd::CreateStatic 来实现它,一旦窗口被拆分,它需要创建一个新视图,但我想使用以前的视图,所以没有人知道如何实现它.谢谢.

I create a MFC MDI application, and want to split a window into two parts at a time dynamically by right click and choosing a "AddSplitWnd" pop menu item. I try to use CSplitterWnd::CreateStatic to implement it, once the window is split, it need to create a new view, but I want to use the previous view instead, so does anyone know how to implement it. Thank you.

推荐答案

这是在 SDI 环境中的拆分器中交换视图的代码片段.这应该也适用于 MDI.

Here is a code snippet to exchange views in a splitter in a SDI environment. This should be adaptable to work in MDI as well.

CView* CDoc::SwitchToView(CView* pNewView)
{
    CFrameWndEx* pMainWnd = (CFrameWndEx*)AfxGetMainWnd();
    CView* pOldActiveView;
    pOldActiveView = pMainWnd->GetActiveView();
    CSplitterWnd* pSplitter = (CSplitterWnd *)pOldActiveView->GetParent();

    // in this case Pane 0,0 is exchanged
    pOldActiveView = (CView*) pSplitter->GetPane(0,0);

    // set flag so that document will not be deleted when view is destroyed
    m_bAutoDelete = FALSE;    
    // Dettach existing view
    RemoveView(pOldActiveView);
    // set flag back to default 
    m_bAutoDelete = TRUE;

    // Set the child window ID of the active view to the ID of the corresponding
    // pane. Set the child ID of the previously active view to some other ID.
    ::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, 0);
    ::SetWindowLong(pNewView->m_hWnd, GWL_ID, pSplitter->IdFromRowCol(0,0));

    // Show the newly active view and hide the inactive view.
    pNewView->ShowWindow(SW_SHOW);
    pOldActiveView->ShowWindow(SW_HIDE);

    // Attach new view
    AddView(pNewView);

    // Set active 
    pSplitter->GetParentFrame()->SetActiveView(pNewView);
    pSplitter->RecalcLayout(); 
    return pOldActiveView;
}

HTH

这篇关于如何在不使用 CSplitterWnd::Create 的情况下在 MFC 中动态拆分窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆