是不是这样子
#include <GuiScrollBars.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$hGui1 = GUICreate('', 400, 300)
GUISetBkColor(0x88AABB)
$Button1 = GUICtrlCreateButton('Button1', 80, 100, 100, 30)
$Button2 = GUICtrlCreateButton('Button2', 250, 100, 100, 30)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
GUIRegisterMsg($WM_VSCROLL, 'WM_VSCROLL')
GUIRegisterMsg($WM_MOUSEWHEEL, 'WM_MOUSEWHEEL')
GUISetState()
_GUIScrollBars_Init($hGui1)
_GUIScrollBars_SetScrollRange($hGui1, $SB_VERT, 0, 50)
_GUIScrollBars_SetScrollRange($hGui1, $SB_HORZ, 0, 50) ;设置水平滚动条参数
While 1
$hGUIMsg = GUIGetMsg()
Switch $hGUIMsg
Case -3
Exit
Case $Button1
GUICtrlSetPos($Button2, Default, 100)
Case $Button2
;~ $iPos = _GUIScrollBars_GetScrollInfoPos($hGui1, $SB_VERT)
GUICtrlSetPos($Button1, Default, 100)
EndSwitch
WEnd
Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam) ;垂直滚动
#forceref $iMsg, $wParam, $lParam
Local $iScrollCode = BitAND($wParam, 0x0000FFFF)
Local $iIndex = -1, $iCharY, $iPosY
Local $iMin, $iMax, $iPage, $iPos, $iTrackPos
For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
$iIndex = $x
$iCharY = $__g_aSB_WindowInfo[$iIndex][3]
ExitLoop
EndIf
Next
If $iIndex = -1 Then Return 0
; 获取垂直滚动条所有信息
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$iMin = DllStructGetData($tSCROLLINFO, 'nMin')
$iMax = DllStructGetData($tSCROLLINFO, 'nMax')
$iPage = DllStructGetData($tSCROLLINFO, 'nPage')
; 保存位置以后进行比较
$iPosY = DllStructGetData($tSCROLLINFO, 'nPos')
$iPos = $iPosY
$iTrackPos = DllStructGetData($tSCROLLINFO, 'nTrackPos')
Switch $iScrollCode
Case $SB_TOP ; 用户点击键盘 HOME 键
DllStructSetData($tSCROLLINFO, 'nPos', $iMin)
Case $SB_BOTTOM ; 用户点击键盘 END 键
DllStructSetData($tSCROLLINFO, 'nPos', $iMax)
Case $SB_LINEUP ; 用户点击向上箭头
DllStructSetData($tSCROLLINFO, 'nPos', $iPos - 1)
Case $SB_LINEDOWN ; 用户点击底部向下箭头
DllStructSetData($tSCROLLINFO, 'nPos', $iPos + 1)
Case $SB_PAGEUP ; 用户点击滚动框内滚动条的上面
DllStructSetData($tSCROLLINFO, 'nPos', $iPos - $iPage)
Case $SB_PAGEDOWN ; 用户点击滚动框内滚动条的下面
DllStructSetData($tSCROLLINFO, 'nPos', $iPos + $iPage)
Case $SB_THUMBTRACK ; 用户拖动滚动条
DllStructSetData($tSCROLLINFO, 'nPos', $iTrackPos)
EndSwitch
; // 设置的位置,然后检索它,
; // 因 Windows 的原因,设定值可能不相同.
DllStructSetData($tSCROLLINFO, 'fMask', $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
;// 如果位置发生了变化, 则滚动窗口并更新
$iPos = DllStructGetData($tSCROLLINFO, 'nPos')
If ($iPos <> $iPosY) Then
_GUIScrollBars_ScrollWindow($hWnd, 0, $iCharY * ($iPosY - $iPos))
$iPosY = $iPos
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_VSCROLL
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
#forceref $iMsg, $wParam
Local $iIndex = -1, $iCharY, $iCharX, $iClientMaxX, $iClientX, $iClientY, $iMax
For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
$iIndex = $x
$iClientMaxX = $__g_aSB_WindowInfo[$iIndex][1]
$iCharX = $__g_aSB_WindowInfo[$iIndex][2]
$iCharY = $__g_aSB_WindowInfo[$iIndex][3]
$iMax = $__g_aSB_WindowInfo[$iIndex][7]
ExitLoop
EndIf
Next
If $iIndex = -1 Then Return 0
Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)
; 检索客户区尺寸.
$iClientX = BitAND($lParam, 0x0000FFFF)
$iClientY = BitShift($lParam, 16)
$__g_aSB_WindowInfo[$iIndex][4] = $iClientX
$__g_aSB_WindowInfo[$iIndex][5] = $iClientY
; 设置垂直滚动范围和页面大小
DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
DllStructSetData($tSCROLLINFO, "nMin", 0)
DllStructSetData($tSCROLLINFO, "nMax", $iMax)
DllStructSetData($tSCROLLINFO, "nPage", $iClientY / $iCharY)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
; 设置水平滚动范围和页面大小
DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
DllStructSetData($tSCROLLINFO, "nMin", 0)
DllStructSetData($tSCROLLINFO, "nMax", 2 + $iClientMaxX / $iCharX)
DllStructSetData($tSCROLLINFO, "nPage", $iClientX / $iCharX)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_SIZE
Func WM_HSCROLL($hWnd, $iMsg, $wParam, $lParam)
#forceref $iMsg, $lParam
Local $iScrollCode = BitAND($wParam, 0x0000FFFF)
Local $iIndex = -1, $iCharX, $iPosX
Local $iMin, $iMax, $iPage, $iPos, $iTrackPos
For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
$iIndex = $x
$iCharX = $__g_aSB_WindowInfo[$iIndex][2]
ExitLoop
EndIf
Next
If $iIndex = -1 Then Return 0
; ; 获取所有的水平滚动条信息
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
$iMin = DllStructGetData($tSCROLLINFO, "nMin")
$iMax = DllStructGetData($tSCROLLINFO, "nMax")
$iPage = DllStructGetData($tSCROLLINFO, "nPage")
; 保存位置以后进行比较
$iPosX = DllStructGetData($tSCROLLINFO, "nPos")
$iPos = $iPosX
$iTrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
#forceref $iMin, $iMax
Switch $iScrollCode
Case $SB_LINELEFT ; 用户点击向左箭头
DllStructSetData($tSCROLLINFO, "nPos", $iPos - 1)
Case $SB_LINERIGHT ; 用户点击向右箭头
DllStructSetData($tSCROLLINFO, "nPos", $iPos + 1)
Case $SB_PAGELEFT ; 用户单击滚动条轴左侧
DllStructSetData($tSCROLLINFO, "nPos", $iPos - $iPage)
Case $SB_PAGERIGHT ; 用户单击滚动条轴右侧
DllStructSetData($tSCROLLINFO, "nPos", $iPos + $iPage)
Case $SB_THUMBTRACK ; 用户拖动滚动条
DllStructSetData($tSCROLLINFO, "nPos", $iTrackPos)
EndSwitch
; // 设置的位置,然后检索它,
; // 因 Windows 的原因,设定值可能不相同.
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
;// 如果位置发生了变化, 则滚动窗口并更新
$iPos = DllStructGetData($tSCROLLINFO, "nPos")
If ($iPos <> $iPosX) Then _GUIScrollBars_ScrollWindow($hWnd, $iCharX * ($iPosX - $iPos), 0)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_HSCROLL
Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) ;设置滚动条鼠标滑轮
#forceref $hWnd, $iMsg, $lParam
Local $updown = BitShift($wParam, 16)
$updown = $updown / 120
Local $iIndex = -1, $iCharY, $iPosY
Local $iMin, $iMax, $iPage, $iPos, $iTrackPos
For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
$iIndex = $x
$iCharY = $__g_aSB_WindowInfo[$iIndex][3]
ExitLoop
EndIf
Next
If $iIndex = -1 Then Return 0
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$iMin = DllStructGetData($tSCROLLINFO, 'nMin')
$iMax = DllStructGetData($tSCROLLINFO, 'nMax')
$iPage = DllStructGetData($tSCROLLINFO, 'nPage')
$iPosY = DllStructGetData($tSCROLLINFO, 'nPos')
$iPos = $iPosY
$iTrackPos = DllStructGetData($tSCROLLINFO, 'nTrackPos')
DllStructSetData($tSCROLLINFO, 'nPos', $iPos - $updown)
DllStructSetData($tSCROLLINFO, 'fMask', $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
$iPos = DllStructGetData($tSCROLLINFO, 'nPos')
If ($iPos <> $iPosY) Then
_GUIScrollBars_ScrollWindow($hWnd, 0, $iCharY * ($iPosY - $iPos))
$iPosY = $iPos
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_MOUSEWHEEL
|