Window Relationship Fundamentals (Windows Embedded CE 6.0)

1/6/2010

When you create a window, you need to specify a window style. The style that you select determines the relationship that the window has with other windows in your application. For example, you can designate a window as a child window of another window by specifying the WS_CHILD style. A child window is a window that appears only within the client area of its parent window. A child window has one parent window only, but a parent window can have any number of child windows, and these, in turn, can have their own child windows.

A child window that can trace a relationship to a parent window through a chain, however long, of parent/child window relationships is said to be a descendant window of the parent window. Likewise, a parent window that can trace a relationship to a child window through a chain of parent/child window relationships is said to be an ancestor window of that child window. To determine whether a window is a descendant window of a specified parent window, call the IsChild function.

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

Windows Embedded CE has rules governing the display and behavior of parent windows and child windows. For example, a child window is positioned relative to the upper-left corner of its parent window's client rectangle. Child windows always are placed directly in front of their parent windows and always are kept with their parent windows in the z-order. When the z-order of a parent window is changed, child windows automatically move with their parent window.

Although you can place or size a child window outside of a parent window, a child window cannot draw any part of itself outside of its parent window's client rectangle. In Windows Embedded CE, a parent window cannot draw on its child windows, and a window cannot draw on sibling windows in front of it. In other words, all of the windows behave as if they have the WS_CLIPCHILDREN and WS_CLIPSIBLINGS styles. You can avoid some of these restrictions by using the GetDCEx function. This function enables you to obtain a handle to a device context for the client area of a specified window and to control how, or whether, clipping occurs. For example, when used with either the WS_CLIPSIBLINGS or DCX_CACHE style, GetDCEx enables a child window to scroll with its parent window.

A window that has no parent window is known as a top-level window. Windows that have the same parent window are known as sibling windows. Even though they might be in different applications, all top-level windows are considered sibling windows. Top-level windows are parented to an invisible dummy root window.

A window can be defined also as the owner of another window; thus, there can be an owner window and an owned window. Although the relationship between an owner window and an owned window is similar to the relationship between a parent window and a child window, there are some differences. For example, the owner/owned window relationship can exist between top-level windows only and, unlike child windows, owned windows can draw outside of their owner windows.

You can create an owner/owned window relationship between top-level windows when you create a window with the WS_POPUP style. Because top-level windows do not have parent windows, the window that you specify as the parent window when you call the CreateWindow function becomes the owner window of the new window. Owned windows, in turn, can own other windows. To retrieve the owner window of a specified window, call the GetParent function. When a window is destroyed, owned windows also are destroyed.

Owner/owned windows move as a group. If you move a window forward in the z-order, its owner window and owned windows move forward with it. Windows Embedded CE places owned windows in front of their owner windows. Although Windows Embedded CE does not prevent you from inserting a top-level window between an owner window and an owned window, Windows Embedded CE does keep owned groups of windows together when one is moved in the z-order. This means that when you change a window's placement in the z-order, Windows Embedded CE displaces any windows between the window and its owner window or owned windows. Moving or sizing a window does not affect the location or size of its owner window or owned windows.

You can create a WS_POPUP window with a NULL owner window. When you do, the window becomes owned partially by the desktop. If Windows Embedded CE moves the desktop to the top of the z-order, these windows remain on top of the desktop. However, if you move the window to the top of the z-order, it does not pull the desktop with it. Threads in the system that usually do not have any kind of window interface use this style when they need to display a message to the user. Owned windows typically do not have taskbar buttons. However, if you create a WS_POPUP window with a NULL owner window, a taskbar button will appear in the taskbar. Be sure that when you specify the WS_POPUP style, you do not specify the WS_CHILD style, too. WS_POPUP windows and WS_CHILD windows are incompatible and should not be used together.

See Also

Concepts

Creating a Window
Working with Windows and Messages

Other Resources

GWES Application Development