Dialog Styles and Dialog Controls

More on Dialog Styles

The style of a dialog is expressed through the keyword "STYLE" within the dialog template. So far, the style that has been used is shown below.


Other window styles may also be supplied. For example, if the dialog is to be given a title bar with a normal border, the style


may be applied. When the style WS_CAPTION (style::caption) is applied, the x and y coordinates used to position the dialog are the coordinates (upper-left corner) of the client area of the dialog relative to its owner's client area. In this case, the title bar of the dialog will reside above the given y-coordinate. When a title bar is present, the dialog box may be moved. The text of the title bar is expressed in the dialog template using the keyword "CAPTION". For example, the sample of the previous section may be adjusted as follows.

DialogIdentity DIALOG  20, 20, 160, 80
 CAPTION "About1"

When a caption is supplied, a system menu may also be supplied using the following style statement.

DialogIdentity DIALOG  20, 20, 160, 80
 CAPTION "About1"

Adding the style WS_THICKFRAME (style::thick_frame) allows the dialog box to be sized. This is somewhat unusual however. The style statement is not required. If it is absent, the default style is WS_POPUP | WS_BORDER (style::popup and style::border).

A menu may be added to a dialog using the "MENU" keyword, as shown below.

MENU menu-name

The menu name that is given is the name of a menu resident in the resource script. The menu name may be character based or of numeric form. Two other keywords are FONT and CLASS. The form of the class keyword is shown below.

CLASS "class-name"

The name that is specified must be the name of a window class that has been or is to be registered.

More on Defining Controls

The keywords for defining controls within a dialog template are shown in the table below.

Control Type Window Class i++ style windows Header
PUSHBUTTON button button_style::push_button | style::Tabstop BS_PUSHBUTTON | WS_TABSTOP
DEFPUSHBUTTON button button_style::push_button_default | style::tabstop BS_DEFPUSHBUTTON | WS_TABSTOP
CHECKBOX button button_style::check_box | style::tabstop BS_CHECKBOX | WS_TABSTOP
RADIOBUTTON button button_style::radio_button | style::tabstop BS_RADIOBUTTON | WS_TABSTOP
GROUPBOX button button_style::group_box | style::tabstop BS_GROUPBOX | WS_TABSTOP
LTEXT static display_style::left | style::group SS_LEFT | WS_GROUP
CTEXT static display_style::center | style::group SS_CENTER | WS_GROUP
RTEXT static display_style::right | style::group SS_RIGHT | WS_GROUP
ICON static display_style::icon SS_ICON
EDITTEXT edit edit_style::left | style::border | style::tabstop ES_LEFT | WS_BORDER | WS_VSCROLL
SCROLLBAR scrollbar scrollbar_style::horizontal SBS_HORZ
LISTBOX listbox listbox_style::notify | style::border | style::vertical_scroll LBS_NOTIFY | WS_BORDER | WS_VSCROLL
COMBOBOX combobox combobox_style::simple CBS_SIMPLE | WS_TABSTOP

In addition to the styles documented in the above table, all controls have the styles WS_CHILD and WS_VISIBLE (style::child and style::visible) applied to them. For control types other than EDITTEXT, SCROLLBAR, LISTBOX and COMBOBOX, the format of the control specification is as shown below.

control-type "text", identity, xPosition, yPosition, xWidth, yheight [,style]
For control types: EDITTEXT, SCROLLBAR, LISTBOX and COMBOBOX, the format of the control specification is shown below.
control-type identity, xPosition, yPosition, xWidth, yheight [,style]

The General Control Statement

Not all possible combinations of creating controls are represented in the table above. The general form of a control statement is shown.

CONTROL "text", identity, "class", style, xPosition, yPosition, xWidth, yWidth

all dialogs may be coded with this statement alone (that is, for the child control windows). For example, instead of using the statement:

PUSHBUTTON "Ok", IDok, 20, 30, 41, 14

the statement:

CONTROL "Ok", IDok, "button", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 20, 30, 41, 14

may be used. When a dialog box is created, the dialog parent is first created; after which, each of the controls is created. The form of the creation for the child windows is shown below (for the above button example):

             style::child | style::visible | button_style::push_button | style::tabstop,
             (20 * character_width) / 4,
             (30 * character_height) / 8,
             (41 * character_width) / 4,
             (14 * character_height) / 8,

where character_width and character_height are the width and height (in pixels) of the font being used for the dialog and dialog_handle is the handle of the parent dialog. The dialog manager issues one create_window call per control present in the dialog template.