Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Create a button inside CWnd

hihahiohihahio Member Posts: 2
Hi,
I have a problem with the CWnd. The question is, can I place a button (or others controls) into the CWnd (or its descendant) object? I have tried to derive a class from CWnd like this:

[code]class CCustomWnd: public CWnd
{
public:
CCustomWnd();

protected:
};[/code]

And in the CCustomWnd constructor, I have dropped code like this:

[code]CCustomWnd:: CCustomWnd ()
{
CButton *button = new CButton();
button->Create("Test Button", WS_VISIBLE | WS_CHILD | WS_BORDER, CRect(10, 10, 50, 30),
this, 1234);
}[/code]

In main dialog initialization function, named CProtoGUIDlg::OnInitDialog(), CCustomWnd object created like this:

[code]BOOL CProtoGuiDlg::OnInitDialog()
{
CDialog::OnInitDialog();

CCustomWnd *page = new CCustomWnd();
page->Create(NULL, "Custom Wnd", WS_VISIBLE | WS_CHILD | WS_BORDER,
CRect(0, 0, 500, 500), this, 1235);

return TRUE;
}[/code]

I think the button will create automatically when CWnd object created, but I wrong. Button does not appear. And then I try to change the code. I remove the button creation process code from the CCustomWnd constructor, and place it on the CProtoGui::OnInitDialog()function like this:

BOOL CProtoGuiDlg::OnInitDialog()
{
CDialog::OnInitDialog();

CCustomWnd *page = new CCustomWnd();
page->Create(NULL, "Custom Wnd", WS_VISIBLE | WS_CHILD | WS_BORDER,
CRect(0, 0, 500, 500), this, 1235);

CButton *button = new CButton();
button->Create("Test Button", WS_VISIBLE | WS_CHILD | WS_BORDER, CRect(10, 10, 50, 30),
page, 1234);

return TRUE;
}

It is work. A button with caption

Comments

Sign In or Register to comment.