CONTROL ADD SCROLLBAR statement

Purpose

Add a scroll bar control to a dialog. A scroll bar allows the user to scroll information left and right, or up and down. Your program, in response to notification messages from the scroll bar control, must do the actual scrolling itself.

Syntax

CONTROL ADD SCROLLBAR, hDlg, id&, txt$, x, y, xx, yy [, [style&] [, [exstyle&]]] [[,] CALL callback]

hDlg 

Handle of the dialog in which the scroll bar will be created. The dialog will become the parent of the control.

id&

Unique identifier for the control in the range 1 to 65535, frequently specified with numeric equates for clarity of the code. For example, the equate %ReportScrollUpDown is more informative than a literal value such as 497. Best practice suggests identifiers should start at 100 to avoid conflict with any of the standard predefined identifiers.

txt$

Text to associate with the scroll bar. A scroll bar control does not display text, so it is possible to use this string for your own purposes; however, an ampersand (&) may be included in txt$ to specify a (hidden) hot-key. See the Remarks section below. Typically, this parameter is specified as an empty string ("") or a $NUL string equate.

x, y

Integer expressions, variables, or numeric literal values, specifying the location of the control inside the dialog client area. x is the horizontal position, and y is the vertical position. 0,0 refers to the upper left corner of the dialog box client area. Coordinates are specified in the same terms (pixels or dialog units) as the parent dialog.

xx 

Integer expression, variable, or numeric literal value, specifying the width of the control. The width is given in the same terms (pixels or dialog units) as the parent dialog.  The most common value used in the Microsoft Dialog Editor and Visual Studio is 10 dialog units.

yy 

Integer expression, variable, or numeric literal value, specifying the height of the control. The height is given in the same terms (pixels or dialog units) as the parent dialog. The most common value used in the Microsoft Dialog Editor and Visual Studio is 11 dialog units.

style&

Primary style of the scroll bar control. The default scroll bar style is %SBS_HORZ; however, if the width is less than the height, the control is automatically switched to %SBS_VERT, regardless of whether %SBS_HORZ is specified or not. If %SBS_VERT is specified, the control will always be created as a vertical scroll bar regardless of the dimensions of the control. The default style is used if both the primary and extended style parameters are omitted from the statement. For example:

CONTROL ADD SCROLLBAR, hDlg, id&, txt$, 100, 100, 150, 14, , , _

  CALL Scrollbar1Callback() ' Use default styles

Custom style values replace the default values. That is, they are not additional to the default style values - your code must specify all necessary primary and extended style parameters.

The primary scroll bar style value can be a combination of any values below, combined together with the OR operator to form a bitmask:

%SBS_BOTTOMALIGN

Align the bottom edge of the scroll bar with the bottom edge of the dialog, and use the default height of system scroll bars. Used with %SBS_HORZ.

%SBS_HORZ

Make the control a horizontal scroll bar (default - see style& above).

%SBS_LEFTALIGN

Align the left edge of the scroll bar with the left edge of the dialog, and use the default width of system scroll bars. Used with %SBS_VERT.

%SBS_RIGHTALIGN

Align the right edge of the scroll bar with the right edge of the dialog, and use the default width of system scroll bars. Used with %SBS_VERT.

%SBS_TOPALIGN

Align the top edge of the scroll bar with the top edge of the window, and use the default height of system scroll bars. Used with %SBS_HORZ.

%SBS_VERT

Make the control a vertical scroll bar (see style& above).

%WS_DISABLED

Create a control that is initially disabled. A disabled control cannot receive input from the user.

%WS_GROUP

Define the start of a group of controls. The first control in each group should also use %WS_TABSTOP style. The next %WS_GROUP control in the tab order defines the end of this group and the start of a new group.

%WS_TABSTOP

Allow the scrollbar control to receive keyboard focus when the user presses the TAB and SHIFT+TAB keys. The TAB key shifts keyboard focus to the next control with the %WS_TABSTOP style, and SHIFT+TAB shifts focus to the previous control with %WS_TABSTOP.

exstyle&

Extended style of the scroll bar control. The default extended scroll bar style comprises %WS_EX_LEFT. The default extended style is used if both the primary and extended style parameters are omitted from the CONTROL ADD SCROLLBAR statement, in the same manner as style& above.

The extended scroll bar style value can be a combination of any values below, combined together with the OR operator to form a bitmask:

%WS_EX_CLIENTEDGE

Apply a sunken edge border to the control.

%WS_EX_LEFT

The control has generic "left-aligned" properties. (default)

%WS_EX_RIGHT

The control has generic "right-aligned" properties. This style has an effect only if the shell language is Hebrew, Arabic, or another language that supports reading order alignment; otherwise, the style is ignored.

%WS_EX_STATICEDGE

Apply a three-dimensional border style to the control (intended to be used for items that do not accept user input).

%WS_EX_WINDOWEDGE

Apply a raised edge border to the control.

callback 

Optional name of a Callback Function that receives all %WM_COMMAND and %WM_NOTIFY messages for the control. See the #MESSAGES metastatement to choose which messages will be received. If a callback for the control is not designated, you must create a dialog Callback Function to process messages from your control.

If the Callback Function processes a message, it should return TRUE (non-zero) to prevent the message being passed unnecessarily to the dialog callback (if one exists). The dialog callback should also return TRUE non-zero) if the notification message is processed by that Callback Function. Otherwise, the DDT engine processes unhandled messages automatically.

Remarks

If the ampersand (&) character appears in the txt$ parameter, the letter that follows will become a control accelerator (hot-key) to enable the user to directly select the scroll bar control, simply by pressing and holding the ALT key while pressing the specified hot-key. For example, "&9" makes ALT+9 the hot-key. The actual text in txt$ is not displayed in a scroll bar control.

When the user clicks on a scroll bar, drags the thumb (also called the scroll box), or initiates a scroll event with the keyboard, a message is sent to the Callback Function designated for the control. If there is no Callback Function designated, the message is sent to the callback for the dialog.

The following notifications are sent to the Callback Function:

%WM_HSCROLL

Sent when the user adjusts a horizontal scroll bar.

%WM_VSCROLL

Sent when the user adjusts a vertical scroll bar.

When a Callback Function receives a %WM_HSCROLL or %WM_VSCROLL message, it should retrieve and set the scroll bar control settings through the GetScrollInfo and SetScrollInfo API function calls. Be sure to use the %SB_CTL flag with these API functions, rather than the %SB_HORZ or %SB_VERT flags.

See also

Dynamic Dialog Tools, CONTROL HANDLE, CONTROL SEND, CONTROL SET COLOR, SCROLLBAR