OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Creating Child Interface Elements

If you do not construct child-window objects in their parent window object's constructor, they will not be automatically created and displayed when the parent is.

You can then create them yourself using TWindow::Create() or, in the case of modal dialog boxes, Execute. In this context, creating means instantiating an interface element.

For example, suppose you have two buttons displayed when the main window is created, one labeled Show and the other labeled Hide. When the user presses the Show button, you want to display a third button labeled Transfer. When the user presses the Hide button, you want to remove the Transfer button:

class TTestWindow : public TFrameWindow
{
TButton *button1, *button2, *button3;
public:
TTestWindow(TWindow *parent, const char far *title);
void
{
if(!button3->HWindow) {
button3->Create();
}
}
void
{
if(button3->HWindow)
button3->Destroy();
}
void
{
}
};
TTestWindow::TTestWindow(TWindow *parent, const char far *title)
{
Init(parent, title);
button1 = new TButton(this, ID_BUTTON1, "Show", 10, 10, 75, 25, false);
button2 = new TButton(this, ID_BUTTON2, "Hide", 95, 10, 75, 25, false);
button3 = new TButton(this, ID_BUTTON3, "Transfer", 180, 10, 75, 25, false);
button3->DisableAutoCreate();
}
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
#define END_RESPONSE_TABLE
Definition eventhan.h:466
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
#define EV_COMMAND(id, method)
Response table entry for a menu/accelerator/push button message.
Definition windowev.h:171

The call to DisableAutoCreate in the constructor prevents the Transfer button from being displayed when TTestWindow is created. The conditional tests in the EvButton1 and EvButton2 functions work by testing the validity of the HWindow data member of the button3 interface object; if the Transfer button is already being displayed, EvButton1 does not try to display it again, and EvButton2 does not try to destroy the Transfer button if it is not being displayed.

See Also