Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SSW_8_11.doc
Скачиваний:
2
Добавлен:
01.05.2025
Размер:
5 Мб
Скачать
☆
    1. The working with slider

The one of most visually good-like controls is a slider control, which also called a trackbar. A "slider control" is a window that contains a slider and optional tick marks. When the user moves the slider, using either the mouse or the arrow keys, the slider control sends notification messages to indicate the change.

Slider controls are useful when you want the user to select a discrete value or a set of consecutive values in a range. For example, you might use a slider control to allow the user to set the repeat rate of the keyboard by moving the slider to a given tick mark.

The slider in a slider control moves in increments that you specify when you create it. For example, if you specify that the slider control should have a range of five, the slider can only occupy six positions: a position at the left side of the slider control and one position for each increment in the range. Typically, each of these positions is identified by a tick mark.

You create a slider by using the constructor and the Create member function of CSliderCtrl. Once you have created a slider control, you can use member functions in CSliderCtrl to change many of its properties. Changes that you can make include setting the minimum and maximum positions for the slider, drawing tick marks, setting a selection range, and repositioning the slider.

BOOL CSliderCtrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,UINT nID);

Parameters:

dwStyle   Specifies the slider control's style. Apply any combination of slider control styles to the control.

rect   Specifies the slider control's size and position. It can be either a CRect object or a RECT structure.

pParentWnd   Specifies the slider control's parent window, usually a CDialog. It must not be NULL.

nID   Specifies the slider control's ID.

Slider controls can have either a vertical or horizontal orientation. They can have tick marks on either side, both sides, or neither. They can also be used to specify a range of consecutive values. These properties are controlled by using slider styles, which you specify when you create the slider control:

  1. TBS_HORZ   Orients the slider horizontally. This is the default orientation.

  2. TBS_VERT   Orients the slider vertically. If you do not specify an orientation, the slider is oriented horizontally.

  3. TBS_AUTOTICKS   Creates a slider that has a tick mark for each increment in its range of values. These tick marks are added automatically when an application calls the SetRange member function. You cannot use the SetTic and SetTicFreq member functions to specify the position of the tick marks if you use this style. Use the ClearTics member function instead.

  4. TBS_NOTICKS   Creates a slider that does not display tick marks.

  5. TBS_BOTTOM   Displays tick marks on the bottom of a horizontal slider. Can be used with the TBS_TOP style to display tick marks on both sides of the slider control.

  6. TBS_TOP   Displays tick marks on the top of a horizontal slider. Can be used with the TBS_BOTTOM style to display tick marks on both sides of the slider control.

  7. TBS_RIGHT   Displays tick marks on the right of a vertical slider. Can be used with the TBS_LEFT style to display tick marks on both sides of the slider control.

  8. TBS_LEFT   Displays tick marks on the left of a vertical slider. Can be used with the TBS_RIGHT style to display tick marks on both sides of the slider control.

  9. TBS_BOTH   Displays tick marks on both sides of the slider in any orientation.

  10. TBS_ENABLESELRANGE   Displays a selection range. When a slider control has this style, the tick marks at the starting and ending positions of a selection range are displayed as triangles (instead of vertical dashes) and the selection range is highlighted. For example, selection ranges might be useful in a simple scheduling application. The user could select a range of tick marks corresponding to hours in a day to identify a scheduled meeting time.

On the slider click, there will be sent the WM_HSCROLL message. To process it. The standard function OnHScroll() is re-defined:

afx_msg void CWnd::OnHScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar );

The parameters are the same as in case of spin, there the vertical scrolling was used.

The functions to work with slider

int CSliderCtrl::GetPos();

This function is called to retrieve the current position of the slider in a slider control.

void CSliderCtrl::SetPos( int nPos );

Here, nPos   Specifies the new slider position.

Call this function to set the current position of the slider in a slider control.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]