A SERVICE OF

logo

By default automatic creation is enabled for all ObjectWindows classes
except for dialog boxes.
TWindow provides two iterator functions, ForEach and FirstThat, that let you
Manipulating child
perform operations on either all the children in the parent’ child list or as
windows
single child at a time. TWindow also provides a number of other functions
that let you determine the number of children in the child list, move
through them one at a time, or move to the top or bottom of the list.
Y u might want to perform some operation on each of a parent window’o s
Operating on all
child windows. The iterator function ForEach takes a pointer to a function.
children: ForEach
The function can be either a member function or a stand-alone function.
The function should take a TWindow
* and a void * argument. ForEach calls
the function once for each child. The child is passed as the TWindow *. The
void * defaults to 0. Y u can use the void * to pass any arguments you wanto
to your function.
After ForEach has called your function, you often need to be careful when
dealing with the child object. Although the object is passed as a TWindow
*,
it is actually usually a descendant of TWindow. T make sure the childo
object is handled correctly you should use the DYNAMIC_CAST macro to,
cast the TWindow
* to a TClass *, where TClass is whatever type the child
object is.
For example, suppose you want to check all the check box child windows
in a parent window:
void
CheckTheBox(TWindow* win, void*)
{
TCheckbox *cb = DYNAMIC_CAST(win, TCheckbox);
if(cb)
cb->Check();
}
void
TMDIFileWindow::CheckAllBoxes()
{
ForEach(CheckTheBox);
}
If the class you’re downcasting to (in this case from a TWindow to a
TCheckbox) is virtually derived from its base, you must use the
DYNAMIC_CAST macro to make the assignment. In this case, TCheckbox
isn’t virtually derived from TWindow, making the DYNAMIC_CAST macro
superfluous in this case.
140
OWL P ogrammer’ Guider s