Parent/Child Relationship

The parent/child relationship between windows is mentioned in OS/2 Version 2.0 - Volume 3: Presentation Manager and Workplace Shell, with regard to the clipping of a child window to the borders of its parent. However, this hierarchy goes further in Presentation Manager, since all windows, both display windows and object windows, have a designated parent window. For top-level display windows, this parent window is the desktop, and is identified by the HWND_DESKTOP constant. Other display windows within an application, which are child windows of the application's main window, may have the top-level application window as their parent, or indeed subsequent levels of the window hierarchy may be created, dependent on application requirements. A window's parent is identified to Presentation Manager by the application when the window is created. Thus the window hierarchy within a particular desktop is dynamically defined at execution time.

As well as being uniquely identified by its window handle, a child window may also be identified by a window identifier, which is unique between children of a particular parent window. This identifier is an integer value, which in practice is usually replaced by a more meaningful symbolic name that defines an integer constant. The window identifier is supplied as a parameter when the application requests creation of the window by Presentation Manager. When a window's parent and identifier are known, the WinWindowFromID() function may be used to determine its window handle so that operations may be performed upon it. See Window Communication for further information.

The parent/child hierarchy is useful for application design purposes, since in many cases, a window and its children may be regarded and manipulated as a single unit. For example, sizing a parent window automatically clips all children of that window to the boundaries of the parent, and closing a parent window results in each of its children being closed. This simplifies the application logic required for applications that create multiple windows.

Frame and Client Windows

The concepts of frame and client areas for a window are discussed in OS/2 Version 2.0 - Volume 3: Presentation Manager and Workplace Shell. In fact, these frame and client areas are separate windows in their own right; the frame window of the application's "main window" is a top-level window with the desktop as its parent, and the client window is a child of the frame window. Frame control windows such as maximize/minimize icons, the title bar, the menu bar, etc., are also separate windows from the application viewpoint, and are regarded as children of the frame window. Note that although they are separate windows, the end user perceives and manipulates the entire group as a single unit.

The frame window and its children all belong to system-defined generic window classes, and thus have their own window procedures defined by Presentation Manager. The exception is the client window, the window class of which is defined by the application; the window procedure is therefore defined to Presentation Manager when the window class is registered. Note that window procedures for system-defined window classes may be subclassed by the application in order to provide specialized processing of certain messages.

The children of a frame window have specific window identifiers assigned to them by Presentation Manager. These window identifiers are unique for each frame window. The predefined window identifiers are shown in Table "Window Identifiers".

These identifiers may be used to communicate with child windows of a particular frame window, without the necessity to determine the window handle of the child window. This concept is applicable to all windows including control windows within a dialog box. See Window Communication for further information.

Object Windows

Object windows do not have a parent in the visual sense, as considerations such as clipping do not arise (since the window is never displayed). For the purposes of standardization, Presentation Manager considers every object window to have a conceptual parent; this parent may be referenced using the constant HWND_OBJECT. This technique allows an object window to be created using the same Presentation Manager function as that used to create a display window. It is also useful in allowing logical grouping of windows with similar functions, or which need to be treated as a group for application purposes, under a single conceptual parent.

For example, all the object windows created by a particular application may be grouped as children of a single "dummy" parent window. When the application terminates and wishes to destroy all these windows, only a single function call to destroy the parent need be issued; Presentation Manager will automatically destroy each of the children in turn before destroying the parent. Due to the way in which Presentation Manager destroys windows by first passing a WM_DESTROY message to the window, each object window is given a chance to exit in an orderly manner.


[Back: Window Hierarchy]
[Next: Window Ownership]