SetScrollPos

王朝百科·作者佚名  2010-02-20  
宽屏版  字体: |||超大  

函数功能:

该函数设置所指定滚动条中的滚动按钮的位置,如果需要,可重绘滚动条以反映出滚动按钮的新位置。该函数提供了向后兼容性,新的应用程序应使用SetScrolllnfo函数。

函数原型:

int SetScrollPos(HWN hWnd,int nBar,int nPos,BOOL bRedraw);

参数:

hWnd:滚动条控制或带有标准滚动条窗体的句柄,由nBar参数值确定。

nBar:指定滚动条将被设置。这个参数可以是下面值,含义如下:

SB_CTL:设置滚动条控制中滚动按钮的位置。而参数hwnd必须是滚动条控制的句柄。

SB_HORZ:设置窗体上标准水平滚动按钮的位置。

SB_VERT:设置窗体上标准垂直滚动按钮的位置。

nPos:指定滚动按钮的新位置。这个位置必须在滚动范围之内。若要了解更多有关滚动范围的信息,请参见SetScrollRange函数。

bRedraw:指定滚动条是否被重画以反映出新的滚动按钮的位置。如果这个参数为TRUE,则滚动条将被重画;为FALSE则滚动条不被重画。

返回值:如果函数运行成功,其返回值是滚动按钮的前一个位置。如果函数运行失败,其返回值是0。若想获得更多的错误信息,请调用GetLastError函数。

Windows XP: 如果the desktop is themed 并且父窗口是一个 message-only window ,则函数返回一个不真实的值。

注意:

如果由于其他并发函数调用,滚动条又被重画,那么设置参数bRedraw为0是非常有必要的。

因为说明滚动条位置的消息WM_HSCROLL和WM_VSCROLL只能为16位数据,那些只依赖于说明位置数据消息的应用程序在函数SetScrollPos的参数nPos中有一个实际最大值。

但是,因为函数SetScrolllnfo,SetScrollPos,SetScrollRange,GetScrollPos, 和 GetScrollRange都支持32位的滚动条位置数据,所以有一个解决16位WM_HSCROLL和WM_VSCROLL消息阻碍的途径,请参见函数GetScrolllnfo的有关技术说明。

速查:Windows NT 3.1、Windows 95、Windows CE 2.0以上,头文件:winuser.h;库文件:user32.lib。

英文原文:

SetScrollPos Function

--------------------------------------------------------------------------------

The SetScrollPos function sets the position of the scroll box (thumb) in the specified scroll bar and, if requested, redraws the scroll bar to reflect the new position of the scroll box.

Note The SetScrollPos function is provided for backward compatibility. New applications should use the SetScrollInfo function.

Syntax

int SetScrollPos( HWND hWnd,

int nBar,

int nPos,

BOOL bRedraw

);

Parameters

hWnd

Handle to a scroll bar control or a window with a standard scroll bar, depending on the value of the nBar parameter.

nBar

Specifies the scroll bar to be set. This parameter can be one of the following values.

SB_CTL

Sets the position of the scroll box in a scroll bar control. The hwnd parameter must be the handle to the scroll bar control.

SB_HORZ

Sets the position of the scroll box in a window's standard horizontal scroll bar.

SB_VERT

Sets the position of the scroll box in a window's standard vertical scroll bar.

nPos

Specifies the new position of the scroll box. The position must be within the scrolling range. For more information about the scrolling range, see the SetScrollRange function.

bRedraw

Specifies whether the scroll bar is redrawn to reflect the new scroll box position. If this parameter is TRUE, the scroll bar is redrawn. If it is FALSE, the scroll bar is not redrawn.

Return Value

If the function succeeds, the return value is the previous position of the scroll box.

Windows XP: If the desktop is themed and the parent window is a message-only window, the function returns an incorrect value.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

If the scroll bar is redrawn by a subsequent call to another function, setting the bRedraw parameter to FALSE is useful.

Because the messages that indicate scroll bar position, WM_HSCROLL and WM_VSCROLL, are limited to 16 bits of position data, applications that rely solely on those messages for position data have a practical maximum value of 65,535 for the SetScrollPos function's nPos parameter.

However, because the SetScrollInfo, SetScrollPos, SetScrollRange, GetScrollInfo, GetScrollPos, and GetScrollRange functions support 32-bit scroll bar position data, there is a way to circumvent the 16-bit barrier of the WM_HSCROLL and WM_VSCROLL messages. See GetScrollInfo for a description of the technique.

If the nBar parameter is SB_CTL and the window specified by the hWnd parameter is not a system scroll bar control, the system sends the SBM_SETPOS message to the window to set scroll bar information. This allows SetScrollPos to operate on a custom control that mimics a scroll bar. If the window does not handle the SBM_SETPOS message, the SetScrollPos function fails.

Function Information

Minimum DLL Version user32.dll

Header Declared in Winuser.h, include Windows.h

Import library User32.lib

Minimum operating systems Windows 95, Windows NT 3.1

See Also

Scroll Bars, GetScrollInfo, GetScrollPos, GetScrollRange, SetScrollInfo, SetScrollRange

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝百科 版权所有