Using Scroll Bar Controls

Top  Previous  Next

About scroll bar

A scroll bar consists of a shaded shaft with an arrow button at each end and a scroll box (sometimes called a thumb) between the arrow buttons. A scroll bar represents the overall length or width of a data object in a window's client area; the scroll box represents the portion of the object that is visible in the client area. The position of the scroll box changes whenever the user scrolls a data object to display a different portion of it. Windows also adjusts the size of a scroll bar's scroll box so that it indicates what portion of the entire data object is currently visible in the window. If most of the object is visible, the scroll box occupies most of the scroll bar's shaft. Similarly, if only a small portion of the object is visible, the scroll box occupies a small part of the shaft.

A scroll bar control is a control that is separate from the window frame and can be placed anywhere in a dialog or window. A scroll bar control appears and functions like a standard scroll bar, but it is a separate window. As a separate window, a scroll bar control receives direct input focus, indicated by a flashing caret displayed in the scroll box. Unlike a standard scroll bar, a scroll bar control also has a built-in keyboard interface that enables the user to direct scrolling. You can use as many scroll bar controls as needed in a single window. When you create a scroll bar control, you must specify the scroll bar's size and position. However, if a scroll bar control's window can be resized, adjustments to the scroll bar's size must be made whenever the size of the window changes.

Creating the control

Scroll bar controls are created through the dialog editor,  manually with the CONTROL statement or by specifying @HSCROLL and @VSCROLL when creating a window.

Scroll bar control styles

The following scroll bat style flags can be specified in the CONTROL statement or by ticking the corresponding check box in the control properties of the dialog editor:

@CTSCROLLHORIZ

Creates a horizontal scroll bar. Automatically set when using the dialog editor.

@CTSCROLLVERT

Creates a vertical scroll bar. Automatically set when using the dialog editor.

@TABSTOP

Moves the input focus between controls if controls are in a dialog. This style has no effect for controls created in a window.

@GROUP

Specifies the first control of a group of controls in which the user can move from one control to the next with the arrow keys. All controls defined without the @GROUP style  after the first control belong to the same group. The next control with the @GROUP style starts the next group (that is, one group ends where the next begins)

Scroll bar control functions and statements

The following EBASIC functions and statements are used to communicate with the scroll bar control.

SETSCROLLRANGE window | dialog, ID, min, max

SETSCROLLRANGE Sets the minimum and maximum range of a scrollbar control to min and max. All values returned by the scrollbar will be between min and max.  If ID = -1 then sets the range of the windows horizontal scrollbar. If ID = -2 then sets the range of the windows vertical scrollbar. ID must be a scrollbar control.

GETSCROLLRANGE window | dialog, ID, varMin, varMax

Stores the scrollbars range into the variables specified by varMin and varMax. The variables must be of type INT. If ID = -1 then stores the range of the windows horizontal scrollbar. If ID = -2 then stores the range of the windows vertical scrollbar. ID must be a scrollbar control. :

SETSCROLLPOS window | dialog, ID, position

Sets the slider position of a scrollbar. If ID = -1 then sets the scroll position of the windows horizontal scrollbar. If ID = -2 then sets the scroll position of the windows vertical scrollbar. Any other ID value is a user-defined scrollbar. Position must be between the minimum and maximum values set by the SETSCROLLRANGE statement.

position = GETSCROLLPOS (window | dialog, ID)

Returns the slider position of a scrollbar. If ID = -1 then returns the scroll position of the windows horizontal scrollbar. If ID = -2 then returns the scroll position of the windows vertical scrollbar. Any other ID value is a user-defined scrollbar.

position = GETTHUMBPOS(window | dialog, ID)

Returns the current thumb track position of a scrollbar. If ID = -1 then returns the thumb track position of the windows horizontal scrollbar. If ID = -2 then returns the thumb track position of the windows vertical scrollbar. Any other ID value is a user-defined scrollbar.

SETCONTROLCOLOR window|dialog, ID, fg, bg

Sets the text color and background color of the scrollbar control.

return = CONTROLEXISTS (window | dialog, ID)

Returns 1 if the control with ID exists in the window or dialog.

ENABLECONTROL window | dialog, ID, 0 | 1

Disables or enables the scrollbar control. If the scrollbar control is disabled no scrolling can be performed and the control will not receive input focus when clicked on.

SETFOCUS window | dialog, ID

Gives the control the input focus. The scrollbar control shows a highlight rectangle in the thumb slider.

SENDMESSAGE window | dialog, msg, wparam, lparam ,ID

Sends a message to the control for advanced functionality.

SHOWWINDOW window, flags, ID

Changes the visibility state of the control. Use @SWHIDE to hide the control and @SWRESTORE to show the control

SETSIZE dialog|window, L, T, W, H ,ID

Changes the size of the control. The scrollbar control is redrawn and the text will be formatted to match the new size of the control. The dimensions include the borders of the control.

Messages

Windows sends two messages to indicate the user has performed and action with the scrollbar.

@IDHSCROLL

This message is sent whenever an action has been performed with either the windows horizontal scroll bar or a horizontal scroll bar created with the CONTROL statement. @CONTROLID will contain the ID of the scroll bar control or 0 for a windows horizontal scroll bar.

@IDVSCROLL

This message is sent whenever an action has been performed with either the windows vertical scroll bar or a vertical scroll bar created with the CONTROL statement. @CONTROLID will contain the ID of the scroll bar control or 0 for a windows vertical scroll bar.

Notification messages

Unlike other controls, a scroll bar returns notification messages in @WPARAM instead of @NOTIFYCODE. Notification messages for scroll bars are sent to inform the program that the user wants to perform an action. It is up to the program to scroll the data and position the scroll box (thumb track) of the scroll bar to the correct position,

@SBLEFT

Scroll to the far left. Sent when the user drags the scroll box to the far left

@SBENDSCROLL

End scroll.

@SBLINELEFT

The user clicked the left scroll arrow.

@SBLINERIGHT

The user clicked the left scroll arrow.

@SBPAGELEFT

Scroll one page left

@SBPAGERIGHT

Scroll one page right

@SBRIGHT

Scroll to the far right. Sent when the user drags the scroll box to the far right

@SBTHUMBPOS

Scroll to absolute position. Use GETTHUMBPOS for the position

@SBTHUMBTRACK

Drag scroll box to a position. Use GETTHUMBPOS for the position

@SBBOTTOM

Scroll to the bottom. Sent when the user drags the scroll bar to the bottom.

@SBLINEDOWN

The user clicks the bottom scroll arrow.

@SBLINEUP

The user clicked the top scroll arrow.

@SBPAGEDOWN

Scroll one page down

@SBPAGEUP

Scroll one page up

@SBTOP

Scroll to the top. Sent when the user drags the scroll box to the top.

The following illustration shows the relationships between the notification codes and the parts of the scroll bars

scrollbars