如何创建跟踪条
在创建跟踪条时,会对其范围和选择范围进行初始化。 页面大小也在此时设置。
需要了解的事项
技术
先决条件
- C/C++
- Windows 用户界面编程
说明
创建跟踪条
以下示例演示如何使用 TBS_AUTOTICKS 和 TBS_ENABLESELRANGE 样式创建跟踪条。
// CreateTrackbar - creates and initializes a trackbar.
//
// Global variable
// g_hinst - instance handle
//
HWND WINAPI CreateTrackbar(
HWND hwndDlg, // handle of dialog box (parent window)
UINT iMin, // minimum value in trackbar range
UINT iMax, // maximum value in trackbar range
UINT iSelMin, // minimum value in trackbar selection
UINT iSelMax) // maximum value in trackbar selection
{
InitCommonControls(); // loads common control's DLL
hwndTrack = CreateWindowEx(
0, // no extended styles
TRACKBAR_CLASS, // class name
"Trackbar Control", // title (caption)
WS_CHILD |
WS_VISIBLE |
TBS_AUTOTICKS |
TBS_ENABLESELRANGE, // style
10, 10, // position
200, 30, // size
hwndDlg, // parent window
ID_TRACKBAR, // control identifier
g_hinst, // instance
NULL // no WM_CREATE parameter
);
SendMessage(hwndTrack, TBM_SETRANGE,
(WPARAM) TRUE, // redraw flag
(LPARAM) MAKELONG(iMin, iMax)); // min. & max. positions
SendMessage(hwndTrack, TBM_SETPAGESIZE,
0, (LPARAM) 4); // new page size
SendMessage(hwndTrack, TBM_SETSEL,
(WPARAM) FALSE, // redraw flag
(LPARAM) MAKELONG(iSelMin, iSelMax));
SendMessage(hwndTrack, TBM_SETPOS,
(WPARAM) TRUE, // redraw flag
(LPARAM) iSelMin);
SetFocus(hwndTrack);
return hwndTrack;
}
相关主题