MFC CView 进入 CDockablePane
Posted
技术标签:
【中文标题】MFC CView 进入 CDockablePane【英文标题】:MFC CView into CDockablePane 【发布时间】:2014-12-06 11:41:30 【问题描述】:我需要将 CView 派生类放入 CDockablePane。是否有任何代码示例,或者有人可以提供这样的代码吗?
我尝试了什么:
显然应该很简单,我在网上找到了类似“只需创建视图并将其父级设置为对话框或可停靠窗格或您想要的窗口类型”的建议。但是由于某种原因它不起作用,也许是因为它需要一个 CFrameWnd,我不知道。
无论如何,我需要能够在不创建另一个文档模板类的情况下做到这一点。只是为了使用预先存在的文档和视图类。
【问题讨论】:
【参考方案1】:这是一个例子:
从 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();
从 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()
【讨论】:
如何将其更改为 FormView?我无法访问 Create 函数,只能访问 CreateEx以上是关于MFC CView 进入 CDockablePane的主要内容,如果未能解决你的问题,请参考以下文章
MFC 10 - 是不是可以在 CView 中有一个 CFrameWnd?