如何写出上下拉动条
如我在各窗口上一列按钮要在下面的代码里加入什么才可以实现通过上下拉动条拉出下面的按钮出来呢
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 221, 377, 206, 130)
$Button1 = GUICtrlCreateButton("Button1", 64, 24, 105, 57)
$Button2 = GUICtrlCreateButton("Button2", 64, 136, 105, 57)
$Button3 = GUICtrlCreateButton("Button3", 64, 232, 105, 57)
$Button4 = GUICtrlCreateButton("Button4", 64, 344, 105, 57)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
$Form1 = GUICreate("Form1", 221, 377, 206, 130)
$Button1 = GUICtrlCreateButton("Button1", 64, 24, 105, 57)
$Button2 = GUICtrlCreateButton("Button2", 64, 136, 105, 57)
$Button3 = GUICtrlCreateButton("Button3", 64, 232, 105, 57)
$Button4 = GUICtrlCreateButton("Button4", 64, 344, 105, 57)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
_GUIScrollBars_Init($Form1, 0, 50) ;初始化滚动条
GUISetState(@SW_SHOW)
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] = $hWnd Then
$index = $x
$yChar = $aSB_WindowInfo[$index]
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] = $hWnd Then
$index = $x
$xClientMax = $aSB_WindowInfo[$index]
$xChar = $aSB_WindowInfo[$index]
$yChar = $aSB_WindowInfo[$index]
$ivMax = $aSB_WindowInfo[$index]
ExitLoop
EndIf
Next
If $index = -1 Then Return 0
Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)
;修正客户区域尺寸
$xClient = BitAND($lParam, 0x0000FFFF)
$yClient = BitShift($lParam, 16)
$aSB_WindowInfo[$index] = $xClient
$aSB_WindowInfo[$index] = $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 虽然是一个简单的滚动条,但是却加了好多代码啊,楼上的代码慢慢研究一下吧。 本帖最后由 华普技术 于 2010-11-30 17:24 编辑
谢谢二楼的讲解不过应该解除太差了不知道如果把拉动条定位到一个组合框里去呢
如以下#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 447, 192, 124)
$Group1 = GUICtrlCreateGroup("Group1", 144, 48, 401, 313)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 176, 112, 81, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox1", 176, 212, 81, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox1", 176, 312, 81, 17)
$Checkbox4 = GUICtrlCreateCheckbox("Checkbox1", 176, 412, 81, 17)
$Checkbox5 = GUICtrlCreateCheckbox("Checkbox1", 176, 512, 81, 17)
$Checkbox6 = GUICtrlCreateCheckbox("Checkbox1", 176, 612, 81, 17)
$Checkbox7 = GUICtrlCreateCheckbox("Checkbox1", 176, 712, 81, 17)
$Checkbox8= GUICtrlCreateCheckbox("Checkbox1", 176, 812, 81, 17)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd如果把拉动条定位在组合框上只拉动组合框内的Checkbox复选框内容呢
真的很头痛 麻烦清楚的大哥们稍微指点下 谢谢了 本帖最后由 yhxhappy 于 2010-12-1 11:51 编辑
将滚动条放在Group里面我也不会,但可以变通一下
写代码的时候我发现个问题,如果$Group1创建在第8行,则会挡住子窗口,不太明白控件的叠放层次是什么定义的,不是后创建处在最上方吗?#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] = $hWnd Then
$index = $x
$yChar = $aSB_WindowInfo[$index]
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] = $hWnd Then
$index = $x
$xClientMax = $aSB_WindowInfo[$index]
$xChar = $aSB_WindowInfo[$index]
$yChar = $aSB_WindowInfo[$index]
$ivMax = $aSB_WindowInfo[$index]
ExitLoop
EndIf
Next
If $index = -1 Then Return 0
Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)
;修正客户区域尺寸
$xClient = BitAND($lParam, 0x0000FFFF)
$yClient = BitShift($lParam, 16)
$aSB_WindowInfo[$index] = $xClient
$aSB_WindowInfo[$index] = $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
页:
[1]