A child window or control is a prepacked window that exists inside and depends on a parent window. Controls reduce repetitive development tasks and promote a consistent and recognisable application interface. The child window processes mouse and keyboard messages and notifies the parent window, by way of command messages when the child window’s state has changed. Child controls are created using the CreatWindowEx() or CreateWindow() function using a predefined class parameter in the CreateWindow call. Windows offers more than 20 types of controls; six, are known as classic controls and are implemented as standard.
Edit Control
An edit or textbox control is used to enter and edit text. The text in the edit controls can be left-justified, right-justified, or centred. Edit controls default to a single line but can be created as multiline. An edit control is limited to about 60 KB of text. If there is a requirement to handle large amounts of text, an enhanced version of the standard edit control known as the rich edit control is available as part of the common control library. The predefined class name for a textbox in the CreatWindow function is "EDIT"
Example
In the following, the user can enter a limited amount of text into the edit box. Clicking the button title 'set title' copies Editbox contents to the static box.
Static Control
Static controls are commonly used as labels for other controls. The static control cannot be selected, accept input from the keyboard or mouse, and does not send WM_COMMAND messages back to the parent window. A static control can display text, shapes, icons or bitmaps. A static window is created using “STATIC” as the window class in the CreateWindow function. For an overview of its configuration and use, see the editbox example (above).
Buttons
A Button is a simple control used to trigger an action. When a button is clicked, it sends a WM_COMMAND message to the parent window.
Push Button- A push or command button is a rectangular clickable window typically containing a text label describing its function. The predefined class name used in the CreateWindow function is "BUTTON". For an overview of its configuration and use, see the editbox example (above).
Check Boxes – A checkbox is a small square box and associated label that describes the purpose of the checkbox. Checkboxes function as a toggle switch allowing the selection and de-selection options. Clicking the box once causes a checkmark to appear; clicking it again toggles the checkmark off. Both of these actions send a message to the parent window. The predefined class name used for a checkbox in the Creatwindow function is "BUTTON" with the dwStyle being set to "BS_CHECKBOX".
Example
In the example below, clicking any checkboxes changes the window's background to a mixture of the corresponding checkbox colour.
Radio Buttons – A radio button allows the user to choose only one of a predefined set of mutually exclusive options. The control consists of a small circle and a descriptive label. Radio buttons are arranged in groups of two or more and are mutually exclusive. When the user selects a particular radio button, any previously selected button in the same group becomes deselected. Unlike checkboxes, radio buttons do not work as toggles. The predefined class name for a radio button in the Creatwindow function is "BUTTON" with the dwStyle being set to "BS_AUTORADIOBUTTON"
Example
In the example below, clicking any radiobutton changes the window's background to the corresponding radiobutton colour.
The Scrollbar
A scroll bar is a control that allows the user to adjust a particular value or a section of the window or view, by navigating either left and right or up and down. A scroll bar appears as a long bar with a small button at each end. Between these buttons, there is a moveable bar called a thumb. Scrollbars can either be integral to the window or be a separate control.
The predefined class for the scrollbar is SCROLLBAR. To add a scrollbar to an existing window add the WS_HSCROLL and WS_VSCROLL parameters to the dwStyle parameter when creating the window.
Example
The following short program demonstrates the main window's vertical scrollbar by displaying the scroll value within the main window.
The Listbox Control
A listbox displays a list of items displayed as a scrollable list within a rectangle. Users can select or deselect one or more of these items by clicking the appropriate line of text. The predefined class for the listbox is “LISTBOX”
Example
The following short program creates a list box and then adds a limited number of selectable items. Clicking any list item results in the selected listview value being copied to the static box.
A Combo Box Control
A combo box or drop-down list is a combination of a listbox and editbox, allowing the user to either type a value directly or select a value from the list. Combo boxes come in three varieties: simple, drop-down, and drop-down list. The predefined class for the scrollbar is “COMBOBOX”
Example
The following short program creates a dropdown list and then adds a limited number of selectable items. Selecting any list item results in the selected value being copied to the static box.