A SERVICE OF

logo

It’ not necessary to call the Windows function Show to display controls.s
Showing controls
Controls are child windows, and Windows automatically displays and
repaints them along with the parent window. Y u can use Show, howevero ,
to hide or reveal controls on demand.
Destroying controls is the parent window’ responsibility The control’s . s
Destroying the
interface element is automatically destroyed along with the parent window
control
when the user closes the window or application. The parent window’s
destructor automatically destroys its child window objects (including child
control objects).
Communicating with control objects
Communication between a window object and its control objects is similar
in some ways to the communication between a dialog box object and its
controls. Like a dialog box, a window needs a mechanism for manipulating
its controls and for responding to control events, such as a list box
selection.
One way dialog boxes manipulate their controls is by sending them
Manipulating
messages using member functions inherited from TWindow (see Chapter 6),
controls
with a control message like LB_ADDSTRING. Control objects greatly
simplify this process by providing member functions that send control
messages for you. TListBox::AddString, for example, takes a string as its
parameter and adds it to the list box by calling the list box object’s
HandleMessage member function:
TListBox::AddString(const char far* str)
{
return (int)HandleMessage(LB_ADDSTRING, 0, (LPARAM)str);
}
This example shows how you can call the control objects’ member
functions via a pointer:
ListBox1->AddString("Atlantic City"); //where ListBox1 is a TListBox *
When a user interacts with a control, Windows sends various control
Responding to
messages. T learn how to respond to control messages, see Chapter 4.o
controls
Chapter 10, Control objects
229