#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>
#Include <Excel.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
HotKeySet('q','quit')
HotKeySet('t','_test')
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
$Form1 = GUICreate("测试", 300, 300)
GUISetState(@SW_SHOW)
$Form2 = GUICreate('',200,200,50,50, $WS_CHILD, $WS_EX_CLIENTEDGE, $Form1)
_GUIScrollBars_Init($Form2)
_GUIScrollBars_SetScrollInfoMax($Form2, $SB_HORZ, 0)
GUISetState(@SW_SHOW,$Form2)
_GUIScrollBars_SetScrollInfoMax($Form2, $SB_VERT, 0)
#cs 研究这个函数的第三个参数
_GUIScrollBars_SetScrollInfoMax($Form2, $SB_VERT, 0)
#ce 研究这个函数的第三个参数
While 1
1
WEnd
Func quit()
Exit
EndFunc
Func _test()
;随机创建 整数个Button
$r = Random(1,10,1);
Local $bt[$r]
;假设每个按钮的高度为20
$bt_heigh = 60
;问题:如何确定这个参数?使得进度条能够刚好符合创建的button个数
;这个参数似乎与控件坐标不是1:1对应的,看帮助文档也没有具体的说明,很迷惑 $what_should_i_send_here
Local $what_should_i_send_here = 60 * $r - 200 ;这样写的结果似乎是错误的
MsgBox(0,'随机创建button个数为:',$r)
_GUIScrollBars_SetScrollInfoMax($Form2, $SB_VERT, $what_should_i_send_here )
GUISwitch($Form2)
For $i = 0 To $r-1
GUICtrlCreateButton(($i+1),1, $i * $bt_heigh , 100,$bt_heigh )
Next
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
; 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