Parent and Child Windows

As previously mentioned, when you create a window, you can designate it as a child of another window by specifying the WS_CHILD style when you call the CreateWindowEx function. A child window has only one parent window. A parent may have any number of child windows and these, in turn, may have their own child windows. Use the IsChild function to determine whether a window is a descendant window of a specified parent window.

You can change the parent window of an existing child window by calling the SetParent function. When you do, the system removes the child window from the client area of the old parent window and moves it to the client area of the new parent window. The GetParent function retrieves the handle to a window's parent window.

A child window is always kept directly in front of its parent window. You cannot place a child window behind its parent or other ancestor window. When the Z order or screen position of a window is changed, its children automatically move along with it. A child window is positioned relative to the upper-left corner of its parent's client rectangle.

Although you may place or size a child windows outside of a parent window, Windows CE does not allow a child window to draw any part of itself outside of its parent's client rectangle. In Windows CE, a parent window can not draw on its children, and a window can not draw on siblings that are in front of it. In other words, all windows behave as if they have the WS_CLIPCHILDREN and WS_CLIPSIBLING styles. You can avoid some of these restrictions by using the GetDCEx function.

When you use DestroyWindow to destroy a window, its children are destroyed as well.