本帖最后由 chzj589 于 2018-7-1 17:55 编辑
要先点击一下窗口里的输入框或按钮,鼠标滚轮才能滚动。修改了一下,可直接滚动
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiScrollBars.au3>
#Region ### START Koda GUI section ### Form=
$hGUI = GUICreate("Form1", 660, 460)
$h_GUIC = GUICreate("Form1", 610, 400, 40, 50,$WS_CHILD, $WS_EX_CLIENTEDGE, $hGUI)
GUISetBkColor(0xFFFBF0)
$Input1 = GUICtrlCreateInput("Input1", 328, 48, 121, 21)
$Button1 = GUICtrlCreateButton("Button1", 336, 120, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 384, 208, 75, 25)
$Button3 = GUICtrlCreateButton("Button3", 304, 256, 75, 25)
$Edit1 = GUICtrlCreateEdit("", 200, 296,380, 950)
GUICtrlSetData(-1, "Edit1")
$Combo1 = GUICtrlCreateCombo("Combo1", 296, 168, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
_GUIScrollBars_Init($h_GUIC)
_GUIScrollBars_SetScrollRange($h_GUIC ,$SB_VERT,0,76);12.5*6.3)
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL");设置滚动条鼠标滑轮
GUISetState(@SW_SHOW, $h_GUIC)
GUISetState(@SW_SHOW, $hGUI)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam)
#forceref $iMsg, $wParam, $lParam
Local $iScrollCode = BitAND($wParam, 0x0000FFFF)
Local $iIndex = -1, $iCharY, $iPosY
Local $iMin, $iMax, $iPage, $iPos, $iTrackPos
For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
$iIndex = $x
$iCharY = $__g_aSB_WindowInfo[$iIndex][3]
ExitLoop
EndIf
Next
If $iIndex = -1 Then Return 0
; Get all the vertial scroll bar information
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$iMin = DllStructGetData($tSCROLLINFO, "nMin")
$iMax = DllStructGetData($tSCROLLINFO, "nMax")
$iPage = DllStructGetData($tSCROLLINFO, "nPage")
; Save the position for comparison later on
$iPosY = DllStructGetData($tSCROLLINFO, "nPos")
$iPos = $iPosY
$iTrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
Switch $iScrollCode
Case $SB_TOP ; user clicked the HOME keyboard key
DllStructSetData($tSCROLLINFO, "nPos", $iMin)
Case $SB_BOTTOM ; user clicked the END keyboard key
DllStructSetData($tSCROLLINFO, "nPos", $iMax)
Case $SB_LINEUP ; user clicked the top arrow
DllStructSetData($tSCROLLINFO, "nPos", $iPos - 1)
Case $SB_LINEDOWN ; user clicked the bottom arrow
DllStructSetData($tSCROLLINFO, "nPos", $iPos + 1)
Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $iPos - $iPage)
Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $iPos + $iPage)
Case $SB_THUMBTRACK ; user dragged the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $iTrackPos)
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
$iPos = DllStructGetData($tSCROLLINFO, "nPos")
If ($iPos <> $iPosY) Then
_GUIScrollBars_ScrollWindow($hWnd, 0, $iCharY * ($iPosY - $iPos))
$iPosY = $iPos
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_VSCROLL
Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) ;设置滚动条鼠标滑轮
#forceref $hWnd, $iMsg, $lParam
Local $updown = BitShift($wParam, 16)
$updown = $updown / 120
Local $iIndex = -1, $iCharY, $iPosY
Local $iMin, $iMax, $iPage, $iPos, $iTrackPos
For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
$iIndex = $x
$iCharY = $__g_aSB_WindowInfo[$iIndex][3]
ExitLoop
EndIf
Next
If $iIndex = -1 Then Return 0
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$iMin = DllStructGetData($tSCROLLINFO, "nMin")
$iMax = DllStructGetData($tSCROLLINFO, "nMax")
$iPage = DllStructGetData($tSCROLLINFO, "nPage")
$iPosY = DllStructGetData($tSCROLLINFO, "nPos")
$iPos = $iPosY
$iTrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
DllStructSetData($tSCROLLINFO, "nPos", $iPos - $updown)
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
$iPos = DllStructGetData($tSCROLLINFO, "nPos")
If ($iPos <> $iPosY) Then
_GUIScrollBars_ScrollWindow($hWnd, 0, $iCharY * ($iPosY - $iPos))
$iPosY = $iPos
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_MOUSEWHEEL
|