
parent windows are displayed. In turn, dialog boxes are child windows
managed by the windows that create them.
When you move or close the parent window the child windows,
automatically close or move with it. The ultimate parent of all child
windows in an application is the main window (there are a couple of
exceptions: you can have windows and dialog boxes without parents and
all main windows are children of the Windows desktop).
When you construct a child-window object, you specify its parent as a
Child-window lists
parameter to its constructor A child-window object keeps track of its.
parent through the Parent data member A parent keeps track of its child-.
window objects in a private data member called ChildList. Each parent
maintains its list of child windows automatically.
Y u can access an object’ child windows using the window iteratoro s
member functions FirstThat and ForEach. See page 140 for more information
on these functions.
As with all interface objects, child-window objects get created in two steps:
Constructing
constructing the interface object and creating the interface element. If you
child windows
construct child-window objects in the constructor of the parent window,
their interface elements are automatically created when the parent is,
assuming that automatic creation is enabled for the child windows. By
default, automatic creation is enabled for all ObjectWindows objects based
on TWindow, with the exception of TDialog. See page 139 for more
information on automatic creation.
For example, the constructor for a window object derived from TWindow
that contains three button child windows would look like this:
TTestWindow::TTestWindow(TWindow *parent, const char far *title)
{
Init(parent, title);
button1 = new TButton(this, ID_BUTTON1, "Show",
190, 270, 65, 20, FALSE);
button2 = new TButton(this, ID_BUTTON2, "Hide",
275, 270, 65, 20, FALSE);
button3 = new TButton(this, ID_BUTTON3, "Transfer",
360, 270, 65, 20, FALSE);
}
Note the use of the this pointer to link the child windows with their parent.
Interface object constructors automatically add themselves to their parents’
child window lists. When an instance of TT stWindow is created, the threee
buttons are automatically displayed in the window.
Chapter 4, Interface objects
137