Using Common Controls in a Dialog Box
The Windows common controls can be used in dialog boxes, form views, record views, and any other window based on a dialog template. The following procedure, with minor changes, will work for forms as well.
To use a common control in a dialog box
Place the control on the dialog template using the dialog editor.
Add to the dialog class a member variable that represents the control. In the Add Member Variable dialog box, check Control variable and ensure that Control is selected for the Category.
If this common control is providing input to the program, declare additional member variable(s) in the dialog class to handle those input values.
You can add these member variables using the context menu in Class View (see Adding a Member Variable).
In OnInitDialog for your dialog class, set the initial conditions for the common control. Using the member variable created in the previous step, use the member functions to set initial value and other settings. See the following descriptions of the controls for details on settings.
You can also use dialog data exchange (DDX) to initialize controls in a dialog box.
In handlers for controls on the dialog box, use the member variable to manipulate the control. See the following descriptions of the controls for details on methods.
The member variable will exist only as long as the dialog box itself exists. You will not be able to query the control for input values after the dialog box has been closed. To work with input values from a common control, override
OnOKin your dialog class. In your override, query the control for input values and store those values in member variables of the dialog class.
You can also use dialog data exchange to set or retrieve values from the controls in a dialog box.
The addition of some common controls to a dialog box will cause the dialog box to no longer function. Refer to Adding Controls to a Dialog Causes the Dialog to No Longer Function for more information on handling this situation.