Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to create a group box programmatically?

2,461 views
Skip to first unread message

Jackson Ho

unread,
Jun 14, 1999, 3:00:00 AM6/14/99
to
I have been trying to create a group box at runtime.
A groupbox is a rectangle that groups other controls together.
The controls are grouped by drawing a border around them and displaying the
given text
in the upper-left corner. You could add this using the Dialog Editor in
Visual C++.

I have tried using the CStatic::Create() and CWnd::CreateEx().
They did create the rectangle but without the top left corner text.
Also, it does not have the 3D style like those created using the Dialog
Editor.

Appreciate any hints and help.


Jackson Ho


Vijayaraghavan Nair

unread,
Jun 15, 1999, 3:00:00 AM6/15/99
to
Hi Jackson,

To create the Group box you have to use the CButton class. One of the button
style BS_GROUPBOX, helps you to create the group box.

May be you can try the following code in the OnInitDialog() of your dialog
class and OnCreate() function of your own derived button class.

////////////////////////////////////////////////////////////////////////////
//////////

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

CGroupButton *m_button;
m_button = new CGroupButton();
CRect m_rec(10,10,150,80);
m_button->Create("Select",WS_CHILD | WS_VISIBLE | BS_GROUPBOX,m_rec,
this, ID_MYBUTTON);

return TRUE;
}

////////////////////////////////////////////////////////////////////////////
//////////////
int CGroupButton::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CButton::OnCreate(lpCreateStruct) == -1)
return -1;

CRect m_rec2(10,20,30,30);
CButton *m_button;
m_button = new CButton();
m_button->Create(NULL, WS_CHILD | WS_VISIBLE | BS_LEFTTEXT
|BS_RADIOBUTTON,m_rec2,
this, ID_MYRADBUTTON);
return 0;
}

////////////////////////////////////////////////////////////////////////////
///////

Hope this helps you

Regards
Vijayaraghavan Nair
Email: Vija...@e-supportpoint.com
www.e-supportpoint.com


Jackson Ho wrote in message ...

Tomas Restrepo

unread,
Jun 15, 1999, 3:00:00 AM6/15/99
to
Jackson,

Just a couple of comments:
You can just look at the .rc file generated for the resource editor to see which
style you're missing in your call to CStatic::Create().
As for the text, Are you calling SetWindowText() after creating the control?


--
Tomas Restrepo
win...@bigfoot.com
http://members.xoom.com/trestrep/

Jackson Ho <jacks...@glenayre.com> wrote in message
news:eobiFJst#GA....@cppssbbsa02.microsoft.com...

0 new messages