
adding buttons dynamically to a dialog
Quote:
> How would I add buttons to a dialog dynamically? (i.e. at runtime as
> opposed to creating them with the resource editor at buildtime?)
> Thanks
Something like the following works for me. I have a handle to the device context which I use
to obtain a window handle, you could however use any of the window handle functions instead.
Simply call CWnd::CreateEx and pass the desired type eg. "BUTTON" or create the control from
CButton and use its Create method.
Note if you want to have edit controls which look 3D you must use the former approach with
extended styles.
CButton *ControlPtr = new CButton(); /* Create new control */
CWnd *myWnd = dc->GetWindow(); /* Get Pointer to Design Window */
if(myWnd && ControlPtr)
{
BOOL Success = ControlPtr->CreateEx(NULL, "BUTTON", "Press Me", WS_CHILD | WS_VISIBLE,
ControlSize, myWnd, ControlID, NULL);
// Where con
if(!Success)
// Deal with error
Quote:
}
--
The Obliterator
(Using VisualC 5.0 SP3)