GUI窗口滑动条无法拖动请高手帮助修正
本帖最后由 17911 于 2010-1-31 11:24 编辑GUI窗口滑动条无法拖动请高手帮助修正错误,看了帮助还是弄不明白
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 391, 195, 192, 124,BitOr($GUI_SS_DEFAULT_GUI,$WS_VSCROLL))
GUISetBkColor(0x6FA1D9)
$Button1 = GUICtrlCreateButton("Button1", 16, -2, 129, 49)
$Button2 = GUICtrlCreateButton("Button2", 16, 62, 129, 57)
$Button3 = GUICtrlCreateButton("Button3", 176, -2, 129, 49)
$Button4 = GUICtrlCreateButton("Button4", 176, 62, 129, 57)
$Button5 = GUICtrlCreateButton("Button5", 16, 150, 129, 57)
$Button6 = GUICtrlCreateButton("Button6", 176, 150, 129, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
论坛 里有相关的例子!你自己搜索一下! 论坛 里有相关的例子!你自己搜索一下!
mkc1989 发表于 2010-1-22 11:26 http://www.autoitx.com/images/common/back.gif
晕,早搜索过了,少的可怜几篇,尤其GUI窗口滚动条,相关提问多数没回复,希望高手帮助 #Include <GuiScrollBars.au3>
_GUIScrollBars_ScrollWindow($hWnd, $iXAmount, $iYAmount)
这个函数中有明确的代码,可以实现拖动。 - -||| 回复 5# xzqd #AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
Opt("MustDeclareVars", 1)
_Main()
Func _Main()
Local $nFileMenu, $nExititem, $GUIMsg, $hGUI, $h_cGUI, $h_cGUI2
Local $listview, $button
$hGUI = GUICreate("ScrollBar Example", 400, 400, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX))
GUISetBkColor(0x88AABB)
$nFileMenu = GUICtrlCreateMenu("File")
$nExititem = GUICtrlCreateMenuItem("Exit", $nFileMenu)
$listview = GUICtrlCreateListView("col1|col2|col3", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
$button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
GUICtrlSetResizing($button, $GUI_DOCKALL)
For $x = 1 To 30
GUICtrlCreateListViewItem("item" & $x & "|col2|col3", $listview)
Next
GUICtrlSetResizing($listview, $GUI_DOCKALL)
$h_cGUI = GUICreate("Child GUI", 200, 200, 10, 200, $WS_CHILD, $WS_EX_CLIENTEDGE, $hGUI)
GUICtrlCreateButton("a button", 10, 10, 90, 20)
GUISetBkColor(0X006400)
GUISetState()
GUICtrlSetResizing($h_cGUI, $GUI_DOCKALL)
GUISwitch($hGUI)
$h_cGUI2 = GUICreate("Child GUI", 200, 200, 215, 10, $WS_CHILD, $WS_EX_CLIENTEDGE, $hGUI)
GUICtrlCreateButton("a button", 10, 10, 90, 20)
GUISetBkColor(0X006400)
GUISetState()
GUICtrlSetResizing($h_cGUI2, $GUI_DOCKALL)
GUISwitch($hGUI)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
GUISetState()
_GUIScrollBars_Init($hGUI)
_GUIScrollBars_Init($h_cGUI)
While 1
$GUIMsg = GUIGetMsg()
Switch $GUIMsg
Case $GUI_EVENT_CLOSE, $nExititem
ExitLoop
EndSwitch
WEnd
Exit
EndFunc ;==>_Main
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)
; Retrieve the dimensions of the client area.
$xClient = BitAND($lParam, 0x0000FFFF)
$yClient = BitShift($lParam, 16)
$aSB_WindowInfo[$index] = $xClient
$aSB_WindowInfo[$index] = $yClient
; Set the vertical scrolling range and page size
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)
; Set the horizontal scrolling range and page size
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 ;==>WM_SIZE
Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)
#forceref $Msg, $lParam
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Local $index = -1, $xChar, $xPos
Local $Min, $Max, $Page, $Pos, $TrackPos
For $x = 0 To UBound($aSB_WindowInfo) - 1
If $aSB_WindowInfo[$x] = $hWnd Then
$index = $x
$xChar = $aSB_WindowInfo[$index]
ExitLoop
EndIf
Next
If $index = -1 Then Return 0
;~ ; Get all the horizontal scroll bar information
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
$Min = DllStructGetData($tSCROLLINFO, "nMin")
$Max = DllStructGetData($tSCROLLINFO, "nMax")
$Page = DllStructGetData($tSCROLLINFO, "nPage")
; Save the position for comparison later on
$xPos = DllStructGetData($tSCROLLINFO, "nPos")
$Pos = $xPos
$TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
#forceref $Min, $Max
Switch $nScrollCode
Case $SB_LINELEFT ; user clicked left arrow
DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
Case $SB_LINERIGHT ; user clicked right arrow
DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box
DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of 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_HORZ, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
;// If the position has changed, scroll the window and update it
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_HSCROLL
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
; 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
帮助里面就有~ 回复 5# xzqd
你用的什么帮助? 学习一下... 上面的代码有点复杂,看不太懂,做好能有个简洁的例子,AU3帮助里没查到用法 本帖最后由 17911 于 2010-1-23 08:39 编辑
#Include
_GUIScrollBars_ScrollWindow($hWnd, $iXAmount, $iYAmount)
这个函数中有明确的代码,可以实现 ...
pusofalse 发表于 2010-1-22 14:03 http://www.autoitx.com/images/common/back.gif
请问这个函数在哪里可以找到,AU3帮助里没有,昨天只弄懂了编辑框滑动条使用,上面的代码看不太懂,昨天查了一上午资料也没弄懂,最做好能简洁一些 哪位高手能帮忙直接编辑一下代码啊,版主的源码太复杂菜鸟有点看不懂, 别的都好说,滚动条的高度或宽度不知道如何控制,改天再研究下 别的都好说,滚动条的高度或宽度不知道如何控制,改天再研究下
afan 发表于 2010-1-29 13:11 http://www.autoitx.com/images/common/back.gif
我就想知道上图中GUI主窗口那个右侧滚动条如何可以实现拖动生效,请老大帮忙编辑一下,越简洁越好,最好用我上面的源码直接编辑,这样我可以看出哪些是经过编辑过的部分,以便学习,太复杂了菜鸟容易看混,谢谢! 本帖最后由 afan 于 2010-1-30 18:05 编辑
回复 12# 17911 #include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
$Form1 = GUICreate("Form1", 391, 195, 192, 124)
GUISetBkColor(0x6FA1D9)
$Button1 = GUICtrlCreateButton("Button1", 16, -2, 129, 49)
$Button2 = GUICtrlCreateButton("Button2", 16, 62, 129, 57)
$Button3 = GUICtrlCreateButton("Button3", 176, -2, 129, 49)
$Button4 = GUICtrlCreateButton("Button4", 176, 62, 129, 57)
$Button5 = GUICtrlCreateButton("Button5", 16, 150, 129, 57)
$Button6 = GUICtrlCreateButton("Button6", 176, 150, 129, 49)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
_GUIScrollBars_Init($Form1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
EndSwitch
WEnd
;================================================================
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 - 18)
DllStructSetData($tSCROLLINFO, "nPage", $xClient / $xChar)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_SIZE
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 ; 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
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 ;==>WM_VSCROLL你要简洁就把==========下面的单独提出来做udf就ok了 回复 你要简洁就把==========下面的单独提出来做udf就ok了
afan 发表于 2010-1-30 18:04 http://www.autoitx.com/images/common/back.gif
谢谢老大,要的就是这个 收下了......................
页:
[1]
2