Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals
- Close it and return to MSVC
11.1.2..The Parent-Child Window Relationship..........................................
There are two types of windows or controls you will deal with in your applications. The
type referred to here is defined by the relationship a window has with regards to other
windows that are part of an application:
?? Parent: a window is referred to as a parent when there are, or there can be, other
windows that depend on it. For example, if you look at the toolbar of Visual
C++, it is equipped with the buttons. The toolbar is a parent to the buttons.
When a parent is created, it "gives life" to other windows that can depend on it.
The most regular parents you will use are forms and dialog boxes.
?? Child: A window is referred to as child when its existence and especially its
visibility depend on another window called its parent. When a parent is created,
made active, or made visible, it gives existence and visibility to its children.
When a parent gets hidden, it also hides its children. If a parent moves, it moves
with its children. The children keep their positions and dimensions inside the
parent. When a parent is destroyed, it also destroys its children (sometimes it
does not happen so smoothly; a parent may make a child unavailable but the
memory space the child was occupying after the parent has been destroyed may
still be use, sometimes filled with garbage, but such memory may not be
available to other applications until you explicitly recover it).
Child controls depend on a parent because the parent "carries", "holds", or hosts
them. All of the Windows controls you will use in your applications are child
controls. A child window can also be a parent of another control. For example,
the Standard toolbar of Visual Studio is the parent of the buttons on it. If you
close or hide the toolbar, its children disappear. At the same time, the toolbar is
a child of the application's frame. If you close the application, the toolbar
disappears, along with its own children. In this example, the toolbar is a child of
the frame but is a parent to its buttons.
It is important to understand that this discussion refers to parents and children as
windows, not as classes: