批量创建控件滚动条问题!
问题1:读取ini批量创建控件,如图所标1处,会空一格位置出来如何解决?
问题2:当批量创建的控件超出时显示一个滚动条供下拉!我调整都会有偏差,要么批量创建一多,拉到最下面就会有一大片空白,要么调整刚好吧,批量创建一多或一少就会有偏差,请大侠帮我弄一下滚动条这问题!
我这个批量创建控件是横排达到8个就会自动换行创建,这个滚动条我实在调整不来, 单个一行一行的我倒是会! 求助啊!
源码和配置文件等相关我用文件夹打包附件上传!
給個代碼你研究;=============
;=釬氪:崦赽梨=
;=============
#include <String.au3>
#include <Date.au3>
#include <GuiConstants.au3>
$dataname = "data.ini"
$softname = IniRead($dataname, "main", "softname", "嗣啋數奀")
$count = IniRead($dataname, "main", "count",1)
$NameVersion = $softname & "v1.0"
If WinExists($NameVersion) Then
MsgBox(16, $NameVersion, "眒冪衄珨跺最唗婓堍俴賸!")
Exit ; 森褐掛眒冪堍俴賸
EndIf
AutoItWinSetTitle($NameVersion)
Global $Paused
;HotKeySet("{f11}", "TogglePause")
HotKeySet("{f10}", "Terminate")
Opt("WinTitleMatchMode", 2);梓枙黍耀宒岆 砩饜
AutoItSetOption("PixelCoordMode", 0);眈勤敦諳黍釴梓晇伎
AutoItSetOption("MouseCoordMode", 0);眈勤敦諳黍扷梓釴梓晇伎
AutoItSetOption("TrayIconHide", 1);笐紲炵苀戲芞梓
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$mygui=GuiCreate($NameVersion,600,500,-1, -1); BitOR($GUI_SS_DEFAULT_GUI,$WS_SYSMENU,$WS_MINIMIZEBOX,$WS_VSCROLL))
;GUISetIcon ("time.ico"); 載蜊芞梓
Dim $Group[$count+1],$Label1[$count+1],$Label2[$count+1],$Label3[$count+1],$Button0[$count+1],$Button1[$count+1]
$rows=4
row();數呾衄撓俴
$i=0
$y=0
Do
$x=0
$y=$y+1
Do
$i=$i+1
$x=$x+1
getdata($i,$x,$y)
Until $x=4 Or $i=$count
Until $i=$count
$Buttonup = GuiCtrlCreateButton("∥",575,445, 20, 20)
$Buttondown = GuiCtrlCreateButton("∣",575,470, 20, 20)
GUICtrlSetState(-1,$GUI_FOCUS)
GuiSetState()
While 1
$msg = GuiGetMsg()
For $i = 1 to $count Step 1
Select
Case $msg = $Button0[$i] ;羲宎數奀
start($i)
Case $msg = $Button1[$i] ;礿砦數奀
stop($i)
Case $msg = $Buttonup
pageup($i)
Case $msg = $Buttondown
pagedown($i)
Case $msg = $GUI_EVENT_CLOSE
Exit 0
Case Else
;;;
EndSelect
Next
WEnd
Exit
#endregion --- GuiBuilder generated code End ---
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func pageup($i)
$if = controlgetpos($NameVersion,"",$Group[$count])
If $if < $rows Then
$Group_xy = controlgetpos($NameVersion,"",$Group[$i])
$Label1_xy = controlgetpos($NameVersion,"",$Label1[$i])
$Label2_xy = controlgetpos($NameVersion,"",$Label2[$i])
$Label3_xy = controlgetpos($NameVersion,"",$Label3[$i])
$Button0_xy = controlgetpos($NameVersion,"",$Button0[$i])
$Button1_xy = controlgetpos($NameVersion,"",$Button1[$i])
GUICtrlSetPos($Group[$i],$Group_xy,$Group_xy+100)
GUICtrlSetPos($Label1[$i],$Label1_xy,$Label1_xy+100)
GUICtrlSetPos($Label2[$i],$Label2_xy,$Label2_xy+100)
GUICtrlSetPos($Label3[$i],$Label3_xy,$Label3_xy+100)
GUICtrlSetPos($Button0[$i],$Button0_xy,$Button0_xy+100)
GUICtrlSetPos($Button1[$i],$Button1_xy,$Button1_xy+100)
EndIf
EndFunc
Func pagedown($i)
$if = controlgetpos($NameVersion,"",$Group[$count])
If $if > 400 Then
$Group_xy = controlgetpos($NameVersion,"",$Group[$i])
$Label1_xy = controlgetpos($NameVersion,"",$Label1[$i])
$Label2_xy = controlgetpos($NameVersion,"",$Label2[$i])
$Label3_xy = controlgetpos($NameVersion,"",$Label3[$i])
$Button0_xy = controlgetpos($NameVersion,"",$Button0[$i])
$Button1_xy = controlgetpos($NameVersion,"",$Button1[$i])
GUICtrlSetPos($Group[$i],$Group_xy,$Group_xy-100)
GUICtrlSetPos($Label1[$i],$Label1_xy,$Label1_xy-100)
GUICtrlSetPos($Label2[$i],$Label2_xy,$Label2_xy-100)
GUICtrlSetPos($Label3[$i],$Label3_xy,$Label3_xy-100)
GUICtrlSetPos($Button0[$i],$Button0_xy,$Button0_xy-100)
GUICtrlSetPos($Button1[$i],$Button1_xy,$Button1_xy-100)
EndIf
EndFunc
Func getdata($i,$x,$y)
$state = IniRead($dataname,"group"&$i,"state","stop")
$starttime = IniRead($dataname,"group"&$i,"starttime","諾玿!")
$stoptime = IniRead($dataname,"group"&$i,"stoptime","")
$Group_x=15+($x-1)*140
$Label_x=25+($x-1)*140
$Button0_x=20+($x-1)*140
$Button1_x=85+($x-1)*140
$Group_y=10+($y-1)*120
$Label1_y=30+($y-1)*120
$Label2_y=50+($y-1)*120
$Label3_y=70+($y-1)*120
$Button_y=90+($y-1)*120
$Group[$i] = GuiCtrlCreateGroup($i&"瘍", $Group_x, $Group_y, 135, 110)
$Label1[$i] = GuiCtrlCreateLabel("諾玿!", $Label_x, $Label1_y, 120, 20)
$Label2[$i] = GuiCtrlCreateLabel("", $Label_x, $Label2_y, 120, 20)
$Label3[$i] = GuiCtrlCreateLabel("", $Label_x, $Label3_y, 120, 20)
$Button0[$i] = GuiCtrlCreateButton("羲宎數奀", $Button0_x, $Button_y, 60, 25)
$Button1[$i] = GuiCtrlCreateButton("礿砦數奀", $Button1_x, $Button_y, 60, 25)
If $state = "start" Then
GUICtrlSetData($Label1[$i],$starttime)
GUICtrlSetData($Label2[$i],"淏婓數奀!")
GUICtrlSetData($Label3[$i],"")
GUICtrlSetBkColor($Group[$i],0x00ff00); 蟯伎
GUICtrlSetColor($Label2[$i],0xff0000) ; 綻伎
GUICtrlSetState($Button0[$i],$GUI_DISABLE)
GUICtrlSetState($Button1[$i],$GUI_ENABLE)
Else
GUICtrlSetState($Button1[$i],$GUI_DISABLE)
GUICtrlSetState($Button0[$i],$GUI_ENABLE)
EndIf
EndFunc
Func start($i)
$starttime = _NowCalc ();
GUICtrlSetData($Label1[$i],$starttime)
GUICtrlSetData($Label2[$i],"淏婓數奀!")
GUICtrlSetData($Label3[$i],"")
GUICtrlSetBkColor($Group[$i],0x00ff00); 蟯伎
GUICtrlSetColor($Label2[$i],0xff0000) ; 綻伎
GUICtrlSetState($Button0[$i],$GUI_DISABLE)
GUICtrlSetState($Button1[$i],$GUI_ENABLE)
IniWrite($dataname,"group"&$i,"state","start")
IniWrite($dataname,"group"&$i,"starttime",$starttime)
EndFunc
Func stop($i)
$starttime = IniRead($dataname,"group"&$i,"starttime",_NowCalc ())
$stoptime = _NowCalc ()
$time = _DateDiff('n',$starttime,$stoptime)
GUICtrlSetData($Label2[$i],$stoptime)
GUICtrlSetData($Label3[$i],"數奀賦彆:"&$time&"煦笘")
GUICtrlSetBkColor($Group[$i],0xe9e5da)
GUICtrlSetColor($Label2[$i],0x000000)
GUICtrlSetColor($Label3[$i],0xff0000)
GUICtrlSetState($Button1[$i],$GUI_DISABLE)
GUICtrlSetState($Button0[$i],$GUI_ENABLE)
IniWrite($dataname,"group"&$i,"state","stop")
IniWrite($dataname,"group"&$i,"stoptime",$stoptime)
IniWrite($dataname,"group"&$i,"time",$time)
EndFunc
Func row()
$rows=$count/4
If $rows > Round($rows) Then
$rows=Round($rows)
Else
$rows=Round($rows)-1
EndIf
$rows=$rows*120+10
EndFunc
;婃礿/閥葩滲杅
Func TogglePause()
$Paused = Not $Paused
While $Paused
Sleep(100)
ToolTip("Paused")
WEnd
ToolTip("")
EndFunc ;==>TogglePause
;豖堤滲杅
Func Terminate()
Exit 0
EndFunc ;==>Terminate如下為配置文件
softname=1
count=20 給個代碼你研究如下為配置文件
txen548 发表于 2015-11-16 21:37 http://www.autoitx.com/images/common/back.gif
非常好的例子! 但前面我发的问题我还是想了解下解决方法,大神们不吝赐教! $var[$i] = GUICtrlCreatePic(@ScriptDir&"\"&$var[$i]&".jpg", $iSpacingX * Mod($i -1, $iNumber) + 16, $iSpacingY * Floor(($i -1) / $iNumber) +16, 66, 66)
GUICtrlSetOnEvent(-1, 'MYGUI_EVENT')
GUICtrlCreateLabel($var[$i], $iSpacingX * Mod($i-1, $iNumber) + 5,$iSpacingY * Floor(($i -1) / $iNumber) + 92, 90, 17, $SS_CENTER) $var[$i] = GUICtrlCreatePic(@ScriptDir&"\"&$var[$i]&".jpg", $iSpacingX * Mod($i -1, $iNumber)...
seniors 发表于 2015-11-17 11:02 http://www.autoitx.com/images/common/back.gif
大神完美的解决了首个空一格的问题!
那么滚动条有没有解决方案? 如果是批量创建图片控件,不如直接用 ListView,会少很多麻烦。
自己加滚动条更适合ListView无法达到,或是不容易达到的效果,比如多种控件按既定的坐标规律组合到一组。只能说,微调滚动条,需要耐心,几年前干过这事… 如果是批量创建图片控件,不如直接用 ListView,会少很多麻烦。
自己加滚动条更适合ListView无法达到,或是 ...
afan 发表于 2015-11-17 16:13 http://www.autoitx.com/images/common/back.gif
那个图片是用来做按钮的! 本帖最后由 seniors 于 2015-11-17 20:31 编辑
刚才的错了,修改一下
自己要多看帮助,就能改好了
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>;子窗口滚动条使用
#include <GUIScrollBars.au3>;子窗口滚动条使用
#include <Array.au3>
#include <StaticConstants.au3>
Opt("GUIOnEventMode", 1)
Global $iNumber = 8 ;每行按钮数量
Global $iSpacingX = 90, $iSpacingY = 108 ;垂直、水平,间距
#Region ### START Koda GUI section ### Form=
$fGUI = GUICreate("Form1", 900, 570)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Button1 = GUICtrlCreateButton("重新加载", 16, 8, 97, 25)
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $cGUI = -1
Global $var
loadconfig()
While 1
Sleep(100)
WEnd
Func Button1Click()
loadconfig()
EndFunc ;==>Button1Click
Func Form1Close()
Exit
EndFunc ;==>Form1Close
Func Form1Maximize()
EndFunc ;==>Form1Maximize
Func Form1Minimize()
EndFunc ;==>Form1Minimize
Func Form1Restore()
EndFunc ;==>Form1Restore
Func loadconfig()
$var = IniReadSection("config.ini", "Eroica") ;Y=每一行的Y坐标,D=行高
If WinExists($cGUI) Then GUIDelete($cGUI)
Local $cGUI_W = 727, $cGUI_H = 446
$cGUI = GUICreate("", $cGUI_W, $cGUI_H, 25, 50, $WS_BORDER + $WS_CHILD, "", $fGUI)
GUISetOnEvent(-3, 'MYGUI_EVENT')
For $i = 1 To $var
GUICtrlCreateLabel($var[$i], $iSpacingX * Mod($i - 1, $iNumber) + 5, $iSpacingY * Floor(($i - 1) / $iNumber) + 92, 90, 17, $SS_CENTER)
$var[$i] = GUICtrlCreatePic(@ScriptDir & "\" & $var[$i] & ".jpg", $iSpacingX * Mod($i - 1, $iNumber) + 16, $iSpacingY * Floor(($i - 1) / $iNumber) + 16, 66, 66)
GUICtrlSetOnEvent(-1, 'MYGUI_EVENT')
Next
GUIRegisterMsg($WM_VSCROLL, "_WM_VSCROLL")
GUISetState()
_GUIScrollBars_Init($cGUI) ;初始化滚动条
_GUIScrollBars_SetScrollRange ( $cGUI, $SB_VERT, 0, $var / $iNumber);最后一个参数是这是总共有几行
_GUIScrollBars_SetScrollInfoPage ( $cGUI, $SB_VERT, 4);最后一个参数是每页有几行
EndFunc ;==>loadconfig
Func MYGUI_EVENT()
For $i = 1 To $var
If @GUI_CtrlId = $var[$i] Then MsgBox(0, "", $var[$i])
Next
EndFunc ;==>MYGUI_EVENT
Func _WM_VSCROLL($hWnd, $Msg, $wParam, $lParam) ;刷新滚动条
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Local $index = -1, $yChar, $yPos
Local $Min, $Max, $Page, $Pos, $TrackPos
For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
If $__g_aSB_WindowInfo[$x] = $hWnd Then
$index = $x
$yChar = $iSpacingY;这个改成你一行的高度是关键
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
DllStructSetData($tSCROLLINFO, "nPos", $Min)
Case $SB_BOTTOM
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 ;==>_WM_VSCROLL
本帖最后由 seniors 于 2015-11-17 20:29 编辑
上面的是一行一行滚动,这个是平滑滚动版本
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>;子窗口滚动条使用
#include <GUIScrollBars.au3>;子窗口滚动条使用
#include <Array.au3>
#include <StaticConstants.au3>
Opt("GUIOnEventMode", 1)
Global $iNumber = 8 ;每行按钮数量
Global $iSpacingX = 90, $iSpacingY = 108 ;垂直、水平,间距
#Region ### START Koda GUI section ### Form=
$fGUI = GUICreate("Form1", 900, 570)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Button1 = GUICtrlCreateButton("重新加载", 16, 8, 97, 25)
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $cGUI = -1
Global $var
loadconfig()
While 1
Sleep(100)
WEnd
Func Button1Click()
loadconfig()
EndFunc ;==>Button1Click
Func Form1Close()
Exit
EndFunc ;==>Form1Close
Func Form1Maximize()
EndFunc ;==>Form1Maximize
Func Form1Minimize()
EndFunc ;==>Form1Minimize
Func Form1Restore()
EndFunc ;==>Form1Restore
Func loadconfig()
$var = IniReadSection("config.ini", "Eroica") ;Y=每一行的Y坐标,D=行高
If WinExists($cGUI) Then GUIDelete($cGUI)
Local $cGUI_W = 727, $cGUI_H = 446
$cGUI = GUICreate("", $cGUI_W, $cGUI_H, 25, 50, $WS_BORDER + $WS_CHILD, "", $fGUI)
GUISetOnEvent(-3, 'MYGUI_EVENT')
For $i = 1 To $var
GUICtrlCreateLabel($var[$i], $iSpacingX * Mod($i - 1, $iNumber) + 5, $iSpacingY * Floor(($i - 1) / $iNumber) + 92, 90, 17, $SS_CENTER)
$var[$i] = GUICtrlCreatePic(@ScriptDir & "\" & $var[$i] & ".jpg", $iSpacingX * Mod($i - 1, $iNumber) + 16, $iSpacingY * Floor(($i - 1) / $iNumber) + 16, 66, 66)
GUICtrlSetOnEvent(-1, 'MYGUI_EVENT')
Next
GUIRegisterMsg($WM_VSCROLL, "_WM_VSCROLL")
GUISetState()
_GUIScrollBars_Init($cGUI) ;初始化滚动条
_GUIScrollBars_SetScrollRange ( $cGUI, $SB_VERT, 0, $var / $iNumber * $iSpacingY);一个参数是这是总共有几行
_GUIScrollBars_SetScrollInfoPage ( $cGUI, $SB_VERT, 4 * $iSpacingY);最后一个参数是每页有几行
EndFunc ;==>loadconfig
Func MYGUI_EVENT()
For $i = 1 To $var
If @GUI_CtrlId = $var[$i] Then MsgBox(0, "", $var[$i])
Next
EndFunc ;==>MYGUI_EVENT
Func _WM_VSCROLL($hWnd, $Msg, $wParam, $lParam) ;刷新滚动条
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Local $index = -1, $yChar, $yPos
Local $Min, $Max, $Page, $Pos, $TrackPos
For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
If $__g_aSB_WindowInfo[$x] = $hWnd Then
$index = $x
$yChar = 1;$iSpacingY;这个改成你一行的高度是关键
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
DllStructSetData($tSCROLLINFO, "nPos", $Min)
Case $SB_BOTTOM
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 ;==>_WM_VSCROLL
上面的是一行一行滚动,这个是平滑滚动版本
seniors 发表于 2015-11-17 20:03 http://www.autoitx.com/images/common/back.gif
$__g_aSB_WindowInfo要求声明变量 ,Local Dim Global 都不行,是否有变量参数? 那个图片是用来做按钮的!
abcd1234 发表于 2015-11-17 19:28 http://www.autoitx.com/images/common/back.gif
单个的控件更建议你用标准的Windows控件ListView 看看这个东西。。。 学习。。。。。。。。。。。。。。。。。 回复 11# abcd1234
把$__g_aSB_WindowInfo改成$aSB_WindowInfo
因为版本不同,所以变量不一样了
页:
[1]
2