A child window is a window that exists inside and is dependent on a parent window. The child window processes mouse and keyboard messages and notifies the parent window when the child window’s state has changed. A standard control is created by instantiating one of the MFC control classes and calling the associated object’s create member function.
Windows makes the classic controls available to the application programs hosted by registering six predefined WNDCLASS’s. The control types, their WNDCLASS’s, and the corresponding MFC classes are shown in the following table.
Control Type | WNDCLASS | MFC Class |
---|---|---|
Buttons | “BUTTON” | CButton |
List boxes | “LISTBOX” | CListBox |
Edit controls | “EDIT” | CEdit |
Combo boxes | “COMBOBOX” | CComboBox |
Scroll bars | “SCROLLBAR” | CScrollBar |
Static controls | “STATIC” | Cstatic |
Buttons
MFC’s CButton class encapsulates the Windows button controls. A Button is a simple control used to trigger an action. The appearance and behaviour of a button control are specified when it is created by including the appropriate style flag in the button’s window style. A button can have many different appearances such as a push-button, radio button, or checkbox.
Checkbox
A checkbox is a small square box with an associated descriptive label. Checkboxes function as a toggle switch allowing the user to select and de-select options. Clicking the box once causes a checkmark to appear; clicking again toggles the checkmark off.
Example
The following short program uses 3 checkboxes to change the window’s background colour. Selecting combinations of each produces a mixture of red green and blue. The initial default background colour is black while selecting all 3 buttons will produce white.
For a further reading on the CButton class
https://docs.microsoft.com/en-us/cpp/mfc/reference/cbutton-class?view=vs-2019
RadioButton
A radio button is a small circular box with an associated descriptive label. Radio buttons normally come in groups that allow the user to choose only one of a predefined set of mutually exclusive options.
Example
The following short program uses 3 radio buttons to change the window’s background colour.
For a further reading on the CButton class
https://docs.microsoft.com/en-us/cpp/mfc/reference/cbutton-class?view=vs-2019
Static control
MFC’s CStatic class encapsulates the Windows static control. Static controls are commonly used as labels for other controls. A static control can display text, shapes, or a picture such as an icon and bitmap. 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.
For further reading on the CStatic classes
https://docs.microsoft.com/en-us/cpp/mfc/reference/cstatic-class?view=vs-2019
Editbox
MFC’s CEdit class encapsulates the functionality of edit controls. Edit controls are used for text entry and editing and come in two varieties: single-line and multiline,
Example
In the following example clicking the button title ‘set button’ changes the contents of the static box to the value of the textbox. The MFC CEdit function GetWindowTextW() and the MFC SetWindowTextW() are used to get and set the contents of both the editbox and staticbox.
For further reading on the CScrollBar class
https://docs.microsoft.com/en-us/cpp/mfc/reference/cscrollbar-class?view=vs-2019
Listbox
MFC’s Clistbox Class encapsulates the Windows listbox control. A listbox displays a list of selectable items in a scrollable box. Users can select or deselect one or more of these items by clicking the appropriate line of text.
Example
The following short program creates a listbox 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. Clicking the button adds a new record, clicking the amend button amends the selected listview value, and clicking the delete button deletes the selected listview item.
For further reading on the CListBox class
https://docs.microsoft.com/en-us/cpp/mfc/reference/clistbox-class?view=vs-2019
Combo Box
MFC’s CComboBox class encapsulates the functionality of the ComboBox controls. A combo box or drop-down list is a combination of listbox and editbox, allowing the user to either type a value directly or select a value from the list. The following list outlines possible combo-box styles.
Example
The following short program displays a dropdown list or combo box. Items can be added deleted or amended by using the textbox and the appropriate button.
For further reading on the CComboBox class
https://docs.microsoft.com/en-us/cpp/mfc/reference/ccombobox-class?view=vs-2019