在刚开始使用SCROLLINFO结构时感觉很不顺手,尤其其中的成员fMask理解不太深刻,经过查询资料才理解一二。
在使用滚动条功能时,如果要设置它的范围和位置可以用以前的函数,例如:SetScrollRange()、 SetScrollPos()、GetScrollRange()、GetScrollPos()等,但目前通常使用SetScrollInfo()与 GetScrollInfo(),使用这两个函数就要用到SCROLLINFO结构。
如果要设置滚动条的范围和页面大小时,可编写以下代码:
si.cbMask = SIF_RANGE | SIF_PAGE ;
si.nMin = 0 ;
si.nMax = NUMLINES - 1 ;
si.nPage = cyClient / cyChar ;
SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
而若要用到滚动条的位置时,可以这样使用:
先si.cbSize = sizeof (si) ;
si.fMask = SIF_ALL ; // 表示Get后将使用si结构的位置、页面大小等量
GetScrollInfo (hwnd, SB_VERT, &si)
然后就可直接使用si.nPos、si.nPage、si.nTrackPos等量,这些量就是从si结构中通过Get函数获得的,
Platform SDK中如下描述:
typedef struct tagSCROLLINFO { // si
UINT cbSize;
UINT fMask;
int nMin;
int nMax;
UINT nPage;
int nPos;
int nTrackPos;
} SCROLLINFO;
typedef SCROLLINFO FAR *LPSCROLLINFO;
Members
cbSize
Specifies the size, in bytes, of this structure.
fMask
Specifies the scroll bar parameters to set or retrieve. This member can be a combination of the following values: Value Meaning
SIF_ALL Combination of SIF_PAGE, SIF_POS, SIF_RANGE, and SIF_TRACKPOS.
SIF_DISABLENOSCROLL This value is used only when setting a scroll bar's parameters. If the scroll bar's new parameters make the scroll bar unnecessary, disable the scroll bar instead of removing it.
SIF_PAGE The nPage member contains the page size for a proportional scroll bar.
SIF_POS The nPos member contains the scroll box position, which is not updated while the user drags the scroll box.
SIF_RANGE The nMin and nMax members contain the minimum and maximum values for the scrolling range.
SIF_TRACKPOS The nTrackPos member contains the current position of the scroll box while the user is dragging it.
nMin
Specifies the minimum scrolling position.
nMax
Specifies the maximum scrolling position.
nPage
Specifies the page size. A scroll bar uses this value to determine the appropriate size of the proportional scroll box.
nPos
Specifies the position of the scroll box.
nTrackPos
Specifies the immediate position of a scroll box that the user is dragging. An application can retrieve this value while processing the SB_THUMBTRACK notification message. An application cannot set the immediate scroll position; the SetScrollInfo function ignores this member.
cbSize: SCROLLINFO结构长度字节数,该值在设置和查询参数时都必须填写。
fMask: 指定结构中的哪些成员是有效,该值共有如下5种选择,可以选择多种用“OR”组合起来,该值在
设置和查询参数时都必须填写。
SIF_ALL :整个结构都有效
SIF_DISABLENOSCROLL:该值仅在设定参数时使用,视控件参数设定的需要来对本结构的成员进行取舍。
SIF_PAGE :nPage成员有效
SIF_POS :nPos成员有效
SIF_RANGE :nMin和nMax成员有效
nMin:滚动范围最小值
nMax:滚动范围最大值
nPage:页尺寸,用来确定比例滚动框的大小
nPos:滚动框的位置
nTrackPos:拖动时滚动框的位置,该参数只能查询,不能设置。