#include <ScrollBarConstants.au3> ;子窗口滚动条使用
#include <GUIScrollBars.au3> ;子窗口滚动条使用
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
$fGUI = GUICreate("XXXX", 600, 400)
$AllCheckbox = GUICtrlCreateCheckbox("全选", 25, 30, 50, 16)
GUISetState()
Local $cGUI_W = 550, $cGUI_H = 320
$cGUI = GUICreate("", 550, 320, 25, 50, $WS_BORDER+$WS_CHILD, "", $fGUI)
Local $Y = 0, $D = 32 ;Y=每一行的Y坐标,D=行高
Local $ButtonArray[1][3]
For $i = 1 To 15
$Checkbox = GUICtrlCreateCheckbox("标题" & $i, 10, $Y+10, 100, 16)
$Button = GUICtrlCreateButton("按钮" & $i, 480, $Y+5, 50, 22)
GUICtrlCreateLabel("", 0, $Y+$D, $cGUI_W, 1) ;分隔线
GUICtrlSetBkColor(-1, 0xdcdcdc)
ReDim $ButtonArray[UBound($ButtonArray)+1][3]
$ButtonArray[UBound($ButtonArray)-1][0] = $Button
$ButtonArray[UBound($ButtonArray)-1][1] = $Checkbox
$Y += $D
Next
$ButtonArray[0][0] = UBound($ButtonArray)-1
If $Y > $cGUI_H Then
_GUIScrollBars_Init($cGUI) ;初始化滚动条
_GUIScrollBars_SetScrollRange($cGUI, $SB_VERT, 0, Round($Y*0.061, 0)) ;设备垂直滚动条参数,高度
_GUIScrollBars_ShowScrollBar($cGUI, $SB_HORZ, False) ;设置水平滚动条隐藏
GUIRegisterMsg($WM_VSCROLL, "_WM_VSCROLL")
EndIf
GUISetState()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case -3
Exit
Case $ButtonArray[1][0] To $ButtonArray[$ButtonArray[0][0]][0]
MsgBox(0, "", '你按下了 "' & GUICtrlRead($Msg) & '"')
Case $AllCheckbox
If GUICtrlRead($AllCheckbox) = 1 Then
$State = $GUI_CHECKED
Else
$State = $GUI_UNCHECKED
EndIf
For $x = 1 To $ButtonArray[0][0]
GUICtrlSetState($ButtonArray[$x][1], $State)
Next
EndSwitch
WEnd
Func _WM_VSCROLL($hWnd, $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
DllStructSetData($tSCROLLINFO, "nPos", $Min)
Case $SB_BOTTOM
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