Windows provides several different window styles that can be combined to form different kinds of windows. The styles are used in the CreateWindow function when the window is created.
An overlapped window is always a top-level window. In other words, an overlapped window never has a parent window. It has a client area, a border, and a title bar. It can also have a System menu, minimize/maximize boxes, scroll bars, and a menu, if these items are specified when the window is created. For windows used as a main interface, the System menu and minimize/maximize boxes are strongly recommended.
Every overlapped window can have a corresponding icon that Windows displays when the window is minimized. A minimized window is not destroyed. It can be opened again by restoring the icon. An application minimizes a window to save screen space when several windows are open at the same time.
You create an overlapped window by using the WS_OVERLAPPED or WS_OVERLAPPEDWINDOW style with the CreateWindow function. An overlapped window created with the WS_OVERLAPPED style always has a caption and a border. The WS_OVERLAPPEDWINDOW style creates an overlapped window with a caption, a thick-frame border, a system menu, and minimize and maximize boxes.
An owned window is a special type of overlapped window. Every owned window has an owner. This owner must also be an overlapped window. Being owned forces several constraints on a window:
An owned window will always be “above” its owner when the windows are ordered. Attempting to move the owner above the owned window will cause the owned window to also change position to ensure that it will always be above its owner.
Windows automatically destroys an owned window when it destroys the window's owner.
An owned window is hidden when its owner is minimized.
An application creates an owned window by specifying the owner's window handle as the hWndParent parameter of the CreateWindow function when creating a window that has the WS_OVERLAPPED style.
Dialog boxes are owned windows by default. The function that creates the dialog box receives the handle of the owner window as its hWndParent parameter.
Pop-up windows are another special type of overlapped window. The main difference between a pop-up window and an overlapped window is that an overlapped window always has a caption, while the caption bar is optional for a pop-up window. Like overlapped windows, pop-up windows can be owned.
You create a pop-up window by using the WS_POPUP window style with the CreateWindow function. A pop-up window can be opened and closed by using the ShowWindow function.
A child window is the window style used for windows that are confined to the client area of a parent window. Child windows are typically used to divide the client area of a parent window into different functional areas.
You create a child window by using the WS_CHILD window style with the CreateWindow function. A child window can be shown and hidden by using the ShowWindow function.
Every child window must have a parent window. The parent window can be an overlapped window, a pop-up window, or even another child window. The parent window relinquishes a portion of its client area to the child window, and the child window receives all input from this area. The window class does not have to be the same for each of the child windows in the parent window. This means an application can fill a parent window with child windows that look different and carry out different tasks.
A child window has a client area, but it does not have any other features unless these are explicitly requested. An application can request a border, title bar, minimize/maximize boxes, and scroll bars for a child window. In most cases, the application designs its own features for the child window.
Although not required, every child window should have a unique integer identifier. The identifier, given in the menu parameter of the CreateWindow function in place of a menu, helps identify the child window when its parent window has many other child windows. The child window should use this identifier in any messages it sends to the parent window. This is the way a parent window with several child windows can identify which child window is sending the message.
Windows always positions the child window relative to the upper-left corner of the parent window's client area. The coordinates are always client coordinates. (For information about mapping, see Section 2.5, “Mapping Functions.”) If all or part of a child window is moved outside the visible portion of the parent window's client area, the child window is clipped; that is, the portion outside the parent window's client area is not displayed.
A child window is an independent window that receives its own input and other messages. Input intended for a child window goes directly to the child window and is not passed through the parent window. The only exception is if input to the child window has been disabled by the EnableWindow function. In this case, Windows passes any input that would have gone to the child window to the parent window instead. This gives the parent window an opportunity to examine the input and enable the child window, if necessary.
Actions that affect the parent window can also affect the child window. The following is a list of actions affecting parent windows that can affect child windows:
Parent Window | Child Window | |
Shown | Shown after the parent window. | |
Hidden | Hidden prior to the parent window being closed. A child window can be visible only when the parent window is visible. | |
Destroyed | Destroyed prior to the parent window being destroyed. | |
Moved | Moved with the parent window's client area. The child window is responsible for painting after the move. | |
Increased in size or maximized | Paints any portions of the parent window that have been exposed as a result of the increased size of the client area. |
Windows does not automatically clip a child window from the parent window's client area. This means the parent window will draw over the child window if it carries out any drawing in the same location as the child window. Windows does clip the child window from the parent window's client area if the parent window has a WS_CLIPCHILDREN style. If the child window is clipped, the parent window cannot draw over it.
A child window can overlap other child windows in the same client area. Two child windows of the same parent window may draw in each other's client area unless one child window has a WS_CLIPSIBLINGS style. Sibling windows are child windows that share the same parent window. If the application specifies this style for a child window, any portion of that child's sibling window that lies within this window will be clipped.
If a window has either the WS_CLIPCHILDREN or WS_CLIPSIBLINGS style, a slight loss in performance occurs.