SetScrollPos

SetScrollPos,該函式設定所指定滾動條中的滾動按鈕的位置,如果需要,可重繪滾動條以反映出滾動按鈕的新位置。

函式功能

該函式設定所指定滾動條中的滾動按鈕的位置,如果需要,可重繪滾動條以反映出滾動按鈕的新位置。該函式提供了向後兼容性,新的應用程式應使用SetScrolllnfo函式。

函式原型

int SetScrollPos(HWND
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為FALSE是非常有必要的。
因為說明滾動條位置的訊息WM_HSCROLL和 WM_VSCROLL只能為16位數據,那些只依賴於說明位置數據訊息的應用程式在函式SetScrollPos的參數nMaxPos中有一個實際最大值65,535 。
但是,因為函式SetScrolllnfo,SetScrollPos, SetScrollRange,GetScrolllnfo,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

相關詞條

相關搜尋

熱門詞條

聯絡我們