[已解决] 控件的位置大于窗口,能如何加竖直滚动条
本帖最后由 kkkpep 于 2012-7-6 15:57 编辑#include <GUIConstantsEx.au3>
GUICreate("test",400,300,-1,-1)
$Button_1 = GUICtrlCreateButton("1",100,20,100,30)
$Button_2 = GUICtrlCreateButton("2",100,120,100,30)
$Button_3 = GUICtrlCreateButton("3",100,220,100,30)
$Button_4 = GUICtrlCreateButton("4",100,320,100,30)
$Button_5 = GUICtrlCreateButton("5",100,420,100,30)
GUISetState()
While 1
$msg = GUIGetMsg()
If$msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
$Button_4 ,$Button_5 超出了窗口无法显示,现在不想改变窗口的大小,如何加竖直滚动条? 回复 1# kkkpep
代码借鉴自帮助的示例, 具体可参考 _GUIScrollBars_Init 的帮助文档.
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
$form = GUICreate("test", 400, 300, -1, -1)
_GUIScrollBars_Init($form, 0, -1)
$Button_1 = GUICtrlCreateButton("1", 100, 20, 100, 30)
$Button_2 = GUICtrlCreateButton("2", 100, 120, 100, 30)
$Button_3 = GUICtrlCreateButton("3", 100, 220, 100, 30)
$Button_4 = GUICtrlCreateButton("4", 100, 320, 100, 30)
$Button_5 = GUICtrlCreateButton("5", 100, 420, 100, 30)
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
GUISetState()
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
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
; 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 回复 2# user3000
这个大小好像是固定的
有没有办法,自动变化?
比如,加2个按钮自动拉长,比如一个不超出则不需要滑动条 回复 3# kkkpep
跟不上你的思维了. 1楼是固定创建了5个按钮控件, 现在 3楼里你不不认为按钮数目不是确定的?
那控件数目及位置到底是怎样决定的?
知道这个条件才能判断如何的'自动变化'吧? 本帖最后由 kkkpep 于 2012-7-5 09:33 编辑
回复 4# user3000
这么说吧 按钮个数不定
可能是2个,可能是5个,或更多
由配置文件来定 回复 5# kkkpep
我无语了, 幸好又无聊.
自己替换2楼代码测试吧, 我得就此打住.
FileDelete('config.ini')
Local $str = '' & @CRLF & _
'1=按钮1' & @CRLF & _
'2=按钮2' & @CRLF & _
'3=按钮3' & @CRLF & _
'4=按钮4' & @CRLF & _
'5=按钮5' & @CRLF & _
'6=按钮6'
FileWrite('config.ini', $str)
Local Const $height = 300
$form = GUICreate("test", 400, $height, -1, -1)
Local $n = IniReadSection('config.ini', 'Button')
If @error Then Local $n = [,, ]
Local $But[$n]
For $i = 1 To $n
$But[$i-1] = GUICtrlCreateButton($n[$i], 100, ($i-1)*100 +20, 100, 30)
Next
Const $v = ($i-1)*100 +20
If $v > $height Then
_GUIScrollBars_Init($form, 0, $v/17)
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
EndIf 本帖最后由 afan 于 2012-7-5 12:55 编辑
这个比较麻烦,很久前我也遇到过这个问题。记得最后是通过计算Gui内控件的最大坐标值为基础来判断是否需要滚动条,以及滚动条的长度的,牵涉到繁琐的微调。
不过,简单的可以通过_GUIScrollBars_SetScrollInfoMax 来进行设置,如:
_GUIScrollBars_SetScrollInfoMax($form, $SB_HORZ, 0)
_GUIScrollBars_SetScrollInfoMax($form, $SB_VERT, 32) 感谢2位老大,看来这个比较复杂,本以为有个三两行代码就能解决,看来超出自己的理解范围了 看不懂···至今没搞定·· 看来不好弄啊,亲自测试看看吧
页:
[1]