【发布时间】:2021-12-13 21:40:15
【问题描述】:
我尝试创建从 CWnd 派生自 CFrameWnd 父级的自定义子窗口。子窗口只是带有边框样式的矩形。子创建在父创建之后。它处理OnCreate 事件。但子窗口不出现。这里有什么问题?
#include <afxwin.h>
class Index: public CWnd
{
public:
Index()
{
CWnd* parentWnd = AfxGetApp()->m_pMainWnd;
Create(
NULL,
NULL,
WS_CHILD | WS_BORDER,
CRect(CPoint(0, 0), CSize(100, 100)),
parentWnd, NULL, NULL);
};
};
class MainFrame: public CFrameWnd
{
public:
MainFrame()
{
Create(
NULL,
"Parent and Child",
WS_OVERLAPPEDWINDOW,
CRect(CPoint(0, 0), CSize(640, 360))
);
};
protected:
afx_msg int OnCreate(LPCREATESTRUCT);
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(MainFrame, CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
int MainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
Index* index = new Index;
index->ShowWindow(SW_NORMAL);
return 0;
};
class Application: public CWinApp
{
BOOL InitInstance()
{
m_pMainWnd = new MainFrame;
m_pMainWnd->ShowWindow(SW_NORMAL);
m_pMainWnd->UpdateWindow();
return true;
};
};
Application app;
【问题讨论】: