5.5 KiB
Track Bar Control
The track bar is generally used for adjusting brightness, volume, etc. In the
situation for adjusting the value in a range, track bar can be used. Calling
CreateWindow function with CTRL_TRACKBAR as the control class name can
create a track bar. Figure 1 shows the typical running effect of a track bar.
Figure 1 Track bar control
Styles of Track Bar
The frequently used combination of styles for a track bar is:
Specifying TBS_NOTIFY style can make a track bar generating notification
messages.
A track bar is horizontal by default. To create a vertical track bar, you can
specify TBS_VERTICAL style. The track bar in Figure 2 is a vertical track
bar.
Figure 2 A vertical track bar
Other styles of track bar are illustrated as follow:
TBS_TIP:Display the tip string beside the track bar (as “Min” and “Max” in Figure 1). A track bar with this style will also display the current position value in the center of the control.TBS_NOTICK:Do not display the tick lines.TBS_BORDER:This style makes a track bar having bordered, which is not used frequently.
Messages of Track Bar
Messages of a track bar are relatively simple, as summarized in the following:
TBM_SETRANGE:Set the minimum and maximum positions for the track bar throughwParamandlParamparameters. The default range is 0~10.TBM_GETMIN:Get the minimum position for the track bar.TBM_GETMAX:Get the maximum position for the track bar.TBM_SETMIN:Set the minimum position for the track bar.TBM_SETMAX:Set the maximum position for the track bar.TBM_SETLINESIZE:Sets the step value bywParamparameter. When the user presses up or down arrow key during the track bar has input focus, the slider will be moved up or down the step value. The default step value is 1.TBM_GETLINESIZE:Gets the step value of the slider.TBM_SETPAGESIZE:Set the page step value bywParamparameter. When the user pressesPageUporPageDownkey during the track bar has input focus, the slider will be moved up or down the page step value. The default page step value is 1.TBM_GETPAGESIZE:Get the page step value of the track bar.TBM_SETPOS:Set the position of the slider.TBM_GETPOS:Get the position of the slider.TBM_SETTICKFREQ:Set the interval value of tick marks in a track bar, the default interval is 1.TBM_GETTICKFREQ:Get the interval value of tick marks in a track bar.TBM_SETTIP:Set the tip string at the minimum and maximum positions.TBM_GETTIP:Set the tip strings at the minimum and maximum positions.
Notification Codes of Track Bar
The track bar with TBS_NOTIFY style may generate the following notification
codes:
TBN_CHANGE:The position of the slider has changed.TBN_REACHMAX:The slider has reached the maximum position.TBN_REACHMIN:The slider has reached the minimum position.
Sample Program
List 1 gives an example program of track bar. The program draws a circle with
the corresponding size according to the current slider position. When the user
changes the position of the slider, the circle will also be refreshed. The
running effect of the program is shown in Figure 3. Please refer to trackbar.c
file of the demo program package mg-samples of this guide for the complete
source code.
List 1 Use of track bar
Figure 3 Use of track bar
-- Main.XiaodongLi - 26 Oct 2009
<< | Table of Contents | >>


