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 that it hosts 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. Checkboxes can be created with the following style
BS_CHECKBOX – Creates a small, empty check box with text. By default, the text is displayed to the right of the check box.
BS_AUTOCHECKBOX – Creates a button that is the same as a check box, except that the check state automatically toggles between checked and cleared each time the user selects the check box.
BS_3STATE – Creates a button that is the same as a check box, except that the box can be grayed as well as checked or cleared.
BS_AUTO3STATE – Creates a button that is the same as a three-state check box, except that the box changes its state when the user selects it. The state cycles through checked, indeterminate, and cleared.
The CEdit member functions GetState() and GetState() can be sued to check/set the state of a button and ON_BN_CLICKED macro maps the button click function to button click event.
For a further reading on the CButton class
https://docs.microsoft.com/en-us/cpp/mfc/reference/cbutton-class?view=vs-2019
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
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.
For further reading on the CComboBox class
https://docs.microsoft.com/en-us/cpp/mfc/reference/ccombobox-class?view=vs-2019
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.
The CComboBox member functions AddString(), DeleteString() and GetLBText() are used to set the add, delete and get the selected listbox content and the ON_LBN_SELCHANGE maps the list box change event to the associated function.