Uredi

Deli z drugimi prek


Dialog Box Controls (C++)

You can add controls to a dialog box using the Dialog Editor tab in the Toolbox window that enables you to choose the control you want and drag it onto the dialog box. By default, the Toolbox window is set to auto hide. It appears as a tab on the left margin of your solution when the Dialog Editor is open. However, you can pin the Toolbox window into position by selecting the Auto Hide button in the upper right corner of the window. For more information on how to control the behavior of this window, see Window Management.

The fastest way to add controls to a dialog box, reposition existing controls, or move controls from one dialog box to another, is to use the drag-and-drop method. The control's position is outlined in a dotted line until it is dropped into the dialog box. When you add a control to a dialog box with the drag-and-drop method, the control is given a standard height appropriate to that type of control.

When you add a control to a dialog box or reposition it, its final placement may be determined by guides or margins, or whether you have the layout grid turned on.

Once you have added a control to the dialog box, you can change properties such as its caption in the Properties Window. You can also select multiple controls and change their properties all at once.

For more information on the Dialog Editor, see how to Add, Edit, or Delete Controls, Layout Controls, and Define Control Access and Values.

For more information on controls and dialogs, see Control Classes, Dialog Box Classes, and Scroll-Bar Styles.

The standard controls available in the Toolbox with default events are:

Control name Default event
Button control BN_CLICKED
Check Box control BN_CLICKED
Combo Box control CBN_SELCHANGE
Edit control EN_CHANGE
Group box (not applicable)
List Box control LBN_SELCHANGE
Radio Button control BN_CLICKED
Static Text control (not applicable)
Picture control (not applicable)
Rich Edit 2.0 control EN_CHANGE
Scroll bar control NM_THEMECHANGED

Note

For more information on using the RichEdit 1.0 control with MFC, see Using the RichEdit 1.0 Control with MFC and Rich Edit Control Examples.

The Windows Common Controls available in the Toolbox to provide increased functionality are:

Control name Default event
Slider control NM_CUSTOMDRAW
Spin control UDN_DELTAPOS
Progress control NM_CUSTOMDRAW
Hot Key control NM_OUTOFMEMORY
List control LVN_ITEMCHANGE
Tree control TVN_SELCHANGE
Tab control TCN_SELCHANGE
Animation control ACN_START
Date Time Picker control DTN_DATETIMECHANGE
Month Calendar control MCN_SELCHANGE
IP Address control IPN_FIELDCHANGED
Extended Combo Box control
Custom control TTN_GETDISPINFO

Custom Controls

The Dialog Editor lets you use existing custom or user controls in a dialog box template.

Note

Custom controls in this sense are not to be confused with ActiveX controls. ActiveX controls were sometimes called OLE custom controls. Also, don't confuse these controls with the owner-drawn controls in Windows.

This functionality is intended to let you use controls other than those supplied by Windows. At run time, the control is associated with a Window class (not the same as a C++ class). A more common way to accomplish the same task is to install any control, such as a static control, in your dialog box. Then at run time, in the OnInitDialog function, remove that control and replace it with your own custom control.

Note

This is an old technique. Today you are advised in most cases to write an ActiveX control or subclass a Windows common control.

For these custom controls, you are limited to:

  • Setting the location in the dialog box.

  • Typing a caption.

  • Identifying the name of the control's Windows class since your application code must register the control by this name.

  • Typing a 32-bit hexadecimal value that sets the control's style.

  • Setting the extended style.

Requirements

Win32

See also

Dialog Editor