回复 1# kkkpep
代码借鉴自帮助的示例, 具体可参考 _GUIScrollBars_Init 的帮助文档.
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
$form = GUICreate("test", 400, 300, -1, -1)
_GUIScrollBars_Init($form, 0, -1)
$Button_1 = GUICtrlCreateButton("1", 100, 20, 100, 30)
$Button_2 = GUICtrlCreateButton("2", 100, 120, 100, 30)
$Button_3 = GUICtrlCreateButton("3", 100, 220, 100, 30)
$Button_4 = GUICtrlCreateButton("4", 100, 320, 100, 30)
$Button_5 = GUICtrlCreateButton("5", 100, 420, 100, 30)
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
GUISetState()
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Func WM_VSCROLL($hWnd, $msg, $wParam, $lParam)
#forceref $Msg, $wParam, $lParam
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Local $index = -1, $yChar, $yPos
Local $Min, $Max, $Page, $Pos, $TrackPos
For $x = 0 To UBound($aSB_WindowInfo) - 1
If $aSB_WindowInfo[$x][0] = $hWnd Then
$index = $x
$yChar = $aSB_WindowInfo[$index][3]
ExitLoop
EndIf
Next
If $index = -1 Then Return 0
; Get all the vertial scroll bar information
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$Min = DllStructGetData($tSCROLLINFO, "nMin")
$Max = DllStructGetData($tSCROLLINFO, "nMax")
$Page = DllStructGetData($tSCROLLINFO, "nPage")
; Save the position for comparison later on
$yPos = DllStructGetData($tSCROLLINFO, "nPos")
$Pos = $yPos
$TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
Switch $nScrollCode
Case $SB_TOP ; user clicked the HOME keyboard key
DllStructSetData($tSCROLLINFO, "nPos", $Min)
Case $SB_BOTTOM ; user clicked the END keyboard key
DllStructSetData($tSCROLLINFO, "nPos", $Max)
Case $SB_LINEUP ; user clicked the top arrow
DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
Case $SB_LINEDOWN ; user clicked the bottom arrow
DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
Case $SB_THUMBTRACK ; user dragged the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
EndSwitch
;~ // Set the position and then retrieve it. Due to adjustments
;~ // by Windows it may not be the same as the value set.
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
;// If the position has changed, scroll the window and update it
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
If ($Pos <> $yPos) Then
_GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
$yPos = $Pos
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_VSCROLL
|