Visual C++ and MFC Fundamentals Chapter 17: Track-Based Controls
- Save All
17.3.3..Slider Properties...................................................................................
After placing a slider control on a form or other host, by default, it assumes a horizontal
position. If you want a vertical slider, change the value of the Orientation property. If
you were dynamically creating the control, its default orientation would be horizontal
whose style is TBS_HORZ. If you want a vertical slider, apply the TBS_VERT style:
BOOL CDlgSlide::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CSliderCtrl *Taskbar = new CSliderCtrl;
Taskbar->Create(WS_CHILD | WS_VISIBLE | TBS_VERT,
CRect(20, 20, 50, 250), this, 0x14);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
The new slider appears as one line, horizontal or vertical, that guides the user with the
area to slide the thumb. When sliding the thumb along the line, the user can set only the
value where the thumb is positioned. Alternatively, if you want the user to be able to
select a range of values instead of just a value, at design time, you can set the Enable
Selection property to True. This is equivalent to adding the
TBS_ENABLESELECTION style. A slider equipped with this style displays a 3-D
“whole” in the body of the slider:
The selection area allows the user to select a range of values.