C ++ MFC功能包->在一个CDialog上创建多个CDockablePanes [英] C++ MFC Feature Pack --> Create multiple CDockablePanes onto an CDialog

查看:305
本文介绍了C ++ MFC功能包->在一个CDialog上创建多个CDockablePanes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在CDialog上创建一个区域,在其中可以放置一些CDockablePanes.这些区域应该可以完全固定在固定的对话框内容上.

I try to create an area onto a CDialog, where I can put some CDockablePanes in. Those shall be perfectly dockable to a fixed dialog content.

我完全想要Codejock对话框窗格示例,但是可以通过MFC Feature Pack类实现: http://codejock.com/downloads/samples/dockingpane.asp

The Codejock Dialog Panes Sample is exactly what I want, but realized with the MFC feature pack classes: http://codejock.com/downloads/samples/dockingpane.asp

此刻,我得到了一个从CFrameWndEx继承的类,该类嵌入在CDialog中.我也有一个工作正常的CDockablePane.我可以取消对接并移动它,但是当我要对接它时,程序崩溃.

At the moment I got a class inherited from CFrameWndEx, which is embedded in the CDialog. I also got a working CDockablePane in it. I can undock it and move it, but when I want to dock it the program crashes.

这是因为可停靠窗格类尝试生成虚拟窗格以预览实际窗格将要到达的位置.它调用GetTopLevelFrame()返回NULL.这样会在afxpane.cpp @CreateEx()中导致崩溃.

This is because the dockable pane class tries to generate a dummy pane for previewing where the real pane would go. It calls GetTopLevelFrame() which returns NULL. This produces the crash in afxpane.cpp @CreateEx().

有人对我有帮助或想法吗? :(

Does someone has any help or ideas for me? :(

问候,


好的,一些代码:
我写了一个继承自CFrameWndEx的小类(因为它的构造函数受到保护):


Okay, some code:
I wrote a little class inherited from CFrameWndEx (because its constructor is protected):

class CMyFrame: public CFrameWndEx  
{  
    public:  
    DECLARE_MESSAGE_MAP()  
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);  
    CDockablePane m_DockWnd; // Will use an own class inherited from CDockablePane later on
};

现在,我将此类嵌入到CDialog中,并将其大小更改为对话框大小:

Now I embedded this class in my CDialog and change its size to the dialogs size:

BOOL CMyDlg::OnInitDialog()  
{      
    CRect wndRect;  
    GetWindowRect(wndRect);    
    m_pFrame = new CMyFrame();  
    m_pFrame->Create(NULL, NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, wndRect, this);  
    m_pFrame->MoveWindow(wndRect);

    CDialog::OnInitDialog();
    ...
}

在CMyFrame类的OnCreate()中,设置CDockablePane并将其停靠:

In the OnCreate() of the CMyFrame class I set up the CDockablePane and dock it:

int CMyFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
        return -1;

    CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));

    EnableDocking(CBRS_ALIGN_ANY);
    // DT_SMART creates dummy dockable panes for previewing the possible position of  
    // the currently floating pane, this leads to a crash at call to GetTopLevelFrame()
    CDockingManager::SetDockingMode(DT_SMART);
    EnableAutoHidePanes(CBRS_ALIGN_ANY);

    // m_DockWnd is a CDockablePane
    if (!m_DockWnd.Create(_T("Test"), this, CRect(0, 0, 200, 200), TRUE, IDC_DOCK_WND, 
        WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
    {
    TRACE0("Failed to create Properties window\n");
    return 1; // failed to create
    }

    m_DockWnd.EnableDocking(CBRS_ALIGN_ANY);
    DockPane(&m_DockWnd);

    return 0;
}

推荐答案

好的,我终于明白了.

我不是由MFC创建dummywnd,而是由我自己创建的.因此,MFC跳过了创建和对GetTopLevelFrame()的调用.

Instead of letting the MFC create the dummywnd, I created it by myself. So the MFC skips the creation and the call to GetTopLevelFrame().

现在的问题是,dummywnd成员变量受到保护,并且没有公共设置方法.所以我继承了一个类,并为自己建立了一个公共设置方法.

Now the problem was, that the dummywnd member variable was protected and had no public set method. So I inherited a class and built myself a public set method.

这篇关于C ++ MFC功能包->在一个CDialog上创建多个CDockablePanes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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