#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>
$GUI = GUICreate("Form1", 700, 500)
GUISetBkColor(0xf3f3f3)
Global $ItemArray[1][4]
_AddGUI($GUI)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $ItemArray[1][0] To $ItemArray[$ItemArray[0][0]][0] ;CHECKBOX
If GUICtrlRead($nmsg) = 1 Then
$v = _ArraySearch($ItemArray, $nMsg, 1, -1, -1, -1, -1, 0)
If $ItemArray[$v][0] = $nMsg Then
GUICtrlSetBkColor($ItemArray[$ItemArray[0][1]][1], $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor($ItemArray[$ItemArray[0][1]][2], 0x0000ff)
GUICtrlSetColor($ItemArray[$ItemArray[0][1]][3], 0x0000ff)
GUICtrlSetBkColor($ItemArray[$v][1], 0x00a8ec)
GUICtrlSetColor($ItemArray[$v][2], 0xffffff)
GUICtrlSetColor($ItemArray[$v][3], 0xffffff)
$ItemArray[0][1] = $v
EndIf
EndIf
EndSwitch
WEnd
Func _AddGUI($GUI)
$Item_GUI = GUICreate("", 550, 400, 120, 70, $WS_CHILD, "", $GUI)
GUISetBkColor(0xffffff)
GUISetState()
Local $ItemNum = 12, $x = 10, $y = 0, $ItemH = 60, $ItemW = 520
For $i = 1 To $ItemNum
GUICtrlCreateGraphic($x, $y+$ItemH, $ItemW, 1, $SS_ETCHEDHORZ) ;建立分割线
ReDim $ItemArray[UBound($ItemArray)+1][4]
$ItemArray[UBound($ItemArray)-1][0] = GUICtrlCreateCheckbox("", $x+5, $y+25, 15, 15) ;CHECKBOX
$ItemArray[UBound($ItemArray)-1][1] = GUICtrlCreateLabel("", $x+30, $y, 490, $ItemH) ;背景框
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateLabel($i & "-" & Random(1111111, 9999999, 1), $x+40, $y+15, 200, 25) ;项目文本
GUICtrlSetFont(-1, 16, 800)
GUICtrlSetColor(-1, 0x0000ff)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlCreateLabel("说明文本:" & Random(1111111, 9999999, 1), $x+40, $y+40, 200, 25) ;项目说明文本
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$ItemArray[UBound($ItemArray)-1][2] = GUICtrlCreateLabel("手动安装", $x+340, $y+22, 50, 20)
GUICtrlSetFont(-1, 9, 400, 4)
GUICtrlSetCursor(-1, 0)
GUICtrlSetColor(-1, 0x0000ff)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$ItemArray[UBound($ItemArray)-1][3] = GUICtrlCreateLabel("自动安装", $x+420, $y+22, 50, 20)
GUICtrlSetFont(-1, 9, 400, 4)
GUICtrlSetCursor(-1, 0)
GUICtrlSetColor(-1, 0x0000ff)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$ItemArray[0][0] = UBound($ItemArray)-1
$y += $ItemH
Next
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
_GUIScrollBars_Init($Item_GUI, 0, $ItemH*$ItemNum*0.059) ;初始化滚动条 上下值的最佳比例是 项目数*单项的高*0.059
GUISwitch($GUI)
EndFunc
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