#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
$Form1 = GUICreate("Form1", 625, 443, -1, -1)
;$Group1 = GUICtrlCreateGroup("", 130, 40, 420, 320)
$Form2 = GUICreate("", 401, 313, 144, 48, $WS_CHILD, "", $Form1);$WS_EX_CLIENTEDGE
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 176, 112, 81, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 176, 212, 81, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 176, 312, 81, 17)
$Checkbox4 = GUICtrlCreateCheckbox("Checkbox4", 176, 412, 81, 17)
$Checkbox5 = GUICtrlCreateCheckbox("Checkbox5", 176, 512, 81, 17)
$Checkbox6 = GUICtrlCreateCheckbox("Checkbox6", 176, 612, 81, 17)
$Checkbox7 = GUICtrlCreateCheckbox("Checkbox7", 176, 712, 81, 17)
$Checkbox8 = GUICtrlCreateCheckbox("Checkbox8", 176, 812, 81, 17)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
_GUIScrollBars_Init($Form2, 0, 50) ;初始化滚动条
GUISwitch($Form1)
$Group1 = GUICtrlCreateGroup("", 127, 40, 420, 323)
GUISetState(@SW_SHOW, $Form1)
GUISetState(@SW_SHOW, $Form2)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
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
;获取所有垂直滚动条信息
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$Min = DllStructGetData($tSCROLLINFO, "nMin")
$Max = DllStructGetData($tSCROLLINFO, "nMax")
$Page = DllStructGetData($tSCROLLINFO, "nPage")
;为稍后进行比较保存位置
$yPos = DllStructGetData($tSCROLLINFO, "nPos")
$Pos = $yPos
$TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
Switch $nScrollCode
Case $SB_TOP ;点击HOME键盘键
DllStructSetData($tSCROLLINFO, "nPos", $Min)
Case $SB_BOTTOM ;点击END键盘键
DllStructSetData($tSCROLLINFO, "nPos", $Max)
Case $SB_LINEUP ;点击顶端箭头
DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
Case $SB_LINEDOWN ;点击底部箭头
DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
Case $SB_PAGEUP ;点击滚动箱上端的快速滚动
DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
Case $SB_PAGEDOWN ;点击滚动箱上端的快速滚动
DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
Case $SB_THUMBTRACK ;拖动滚动箱
DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
EndSwitch
;~ // 设置位置然后修正它. 由于窗口的调整可能会和设置的值不同.
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
;// 如果位置改变, 滚动窗口并升级
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
If ($Pos <> $yPos) Then
_GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
$yPos = $Pos
EndIf
Return $GUI_RUNDEFMSG
EndFunc
Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) ;设置窗口尺寸
#forceref $Msg, $wParam
Local $index = -1, $yChar, $xChar, $xClientMax, $xClient, $yClient, $ivMax
For $x = 0 To UBound($aSB_WindowInfo) - 1
If $aSB_WindowInfo[$x][0] = $hWnd Then
$index = $x
$xClientMax = $aSB_WindowInfo[$index][1]
$xChar = $aSB_WindowInfo[$index][2]
$yChar = $aSB_WindowInfo[$index][3]
$ivMax = $aSB_WindowInfo[$index][7]
ExitLoop
EndIf
Next
If $index = -1 Then Return 0
Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)
;修正客户区域尺寸
$xClient = BitAND($lParam, 0x0000FFFF)
$yClient = BitShift($lParam, 16)
$aSB_WindowInfo[$index][4] = $xClient
$aSB_WindowInfo[$index][5] = $yClient
;设置垂直滚动范围和页面大小
DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
DllStructSetData($tSCROLLINFO, "nMin", 0)
DllStructSetData($tSCROLLINFO, "nMax", $ivMax)
DllStructSetData($tSCROLLINFO, "nPage", $yClient / $yChar)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
;设置水平滚动范围和页面大小
DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
DllStructSetData($tSCROLLINFO, "nMin", 0)
DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar)
DllStructSetData($tSCROLLINFO, "nPage", $xClient / $xChar)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
Return $GUI_RUNDEFMSG
EndFunc