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.

STYLE WS_POPUP | WS_DLGFRAME

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

STYLE WS_POPUP | WS_CAPTION

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
 STYLE WS_POPUP | WS_CAPTION
 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
 STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "About1"
{
 ....
}

Adding the style WS_THICKFRAME (style::ThickFrame) 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::PushButton | style::Tabstop BS_PUSHBUTTON | WS_TABSTOP
DEFPUSHBUTTON button button_style::PushButtonDefault | style::Tabstop BS_DEFPUSHBUTTON | WS_TABSTOP
CHECKBOX button button_style::CheckBox | style::Tabstop BS_CHECKBOX | WS_TABSTOP
RADIOBUTTON button button_style::RadioButton | style::Tabstop BS_RADIOBUTTON | WS_TABSTOP
GROUPBOX button button_style::GroupBox | 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):

create_window(Buttonwclassname,
             "Ok",
             style::Child | style::Visible | button_style::PushButton | style::Tabstop,
             (20 * CharacterWidth) / 4,
             (30 * Characterheight) / 8,
             (41 * CharacterWidth) / 4,
             (14 * Characterheight) / 8,
             DialogHandle,
             item_identity::ok,
             Instance,
             (void*)null);

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