gpt4 book ai didi

c++ - MFC CView 到 CDockablePane

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:41:42 26 4
gpt4 key购买 nike

我需要将 CView 派生类放入 CDockablePane 中。某处有任何代码示例,或者有人可以提供这样的代码吗?

我尝试过的:

显然应该很简单,我在网上找到了诸如“只需创建 View 并将其父项设置为对话框或可停靠 Pane 或您想要的窗口类型”之类的建议。但由于某种原因它不起作用,也许是因为它需要一个 CFrameWnd,我不知道。

无论如何,我需要能够在不创建另一个文档模板类的情况下执行此操作。只是为了使用预先存在的文档和 View 类。

最佳答案

这是一个例子:

派生自 CDockablePane 的类:

//CRichEditPane.h

class CRichEditPane : public CDockablePane
{
DECLARE_DYNAMIC(CRichEditPane)

public:
CRichEditPane();
virtual ~CRichEditPane();

protected:
void AdjustLayout();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
};

//CRichEditPane.cpp

IMPLEMENT_DYNAMIC(CRichEditPane, CDockablePane)

CRichEditPane::CRichEditPane()
{

}

CRichEditPane::~CRichEditPane()
{
}


BEGIN_MESSAGE_MAP(CRichEditPane, CDockablePane)
ON_WM_CREATE()
ON_WM_SIZE()
END_MESSAGE_MAP()


// CRichEditPane message handlers


int CRichEditPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;

CRuntimeClass *pClass = RUNTIME_CLASS(CRichEditViewInPane);

// calling constructor using IMPLEMENT_DYNCREATE macro
CRichEditViewInPane *pView = (CRichEditViewInPane*)pClass->CreateObject();


if (!pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0,0,0,0), this, AFX_IDW_PANE_FIRST, NULL))
{
return -1;
}

CRichEditCtrl ctrl;
ctrl.Create(WS_CHILD, CRect(0, 0, 0, 0), this, 10991);

return 0;
}


void CRichEditPane::OnSize(UINT nType, int cx, int cy)
{
CDockablePane::OnSize(nType, cx, cy);

AdjustLayout();
}

a view class derived from CView:

//CRichEditViewInPane.h

class CRichEditViewInPane : public CRichEditView
{
DECLARE_DYNCREATE(CRichEditViewInPane)

protected:
CRichEditViewInPane(); // protected constructor used by dynamic creation
virtual ~CRichEditViewInPane();

public:
#ifdef _DEBUG
virtual void AssertValid() const;
#ifndef _WIN32_WCE
virtual void Dump(CDumpContext& dc) const;
#endif
#endif

protected:
DECLARE_MESSAGE_MAP()
};

//CRichEditViewInPane. cpp

IMPLEMENT_DYNCREATE(CRichEditViewInPane, CRichEditView)

CRichEditViewInPane::CRichEditViewInPane()
{

}

CRichEditViewInPane::~CRichEditViewInPane()
{
}

BEGIN_MESSAGE_MAP(CRichEditViewInPane, CRichEditView)
END_MESSAGE_MAP()

关于c++ - MFC CView 到 CDockablePane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27331291/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com