MyEarth Posted December 6, 2014 Posted December 6, 2014 (edited) Hi all check my script: #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("", 325, 72, -1, -1) $Progress = GUICtrlCreateProgress(8, 8, 300, 17, $PBS_SMOOTH) $Label = GUICtrlCreateLabel("", 8, 30, 1, 17) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetState(-1, $GUI_HIDE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Local $Count = 10, $Set GUICtrlSetState($Label, $GUI_SHOW) For $i = 1 To $Count $Set = Int($i / ($Count) * 100) GUICtrlSetPos($Label, 8, 30, $Set, 17) ConsoleWrite("$ProgressSet: " & $Set & @CR) GUICtrlSetData($Progress, $Set) Sleep(500) Next Exit EndSwitch WEnd First I don't know how to calculate the correct size for $Label using $Set, secondly i don't know how to make the process from a size to a new size "smoother", GUICtrlSetPos don't have a speed parameter or similar Thanks Edited December 6, 2014 by MyEarth
MyEarth Posted December 6, 2014 Author Posted December 6, 2014 (edited) For the first point, i have probably an answer. If $Set = percentage of the progressbar, so the width of $Label is equal to total size minus that percentage, like: ($LabelWidth * $Set) / 100 ; $LabelWidth = 300 in the example on the first post If isn't right please correct me. Still have no idea for make the "transition" smooth Edited December 6, 2014 by MyEarth
mikell Posted December 6, 2014 Posted December 6, 2014 ? #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> $width = 300 $hGUI = GUICreate("", 325, 72, -1, -1) $Progress = GUICtrlCreateProgress(8, 8, $width, 17, $PBS_SMOOTH) $Label = GUICtrlCreateLabel("", 8, 30, 1, 17) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetState(-1, $GUI_HIDE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Local $Count = $width, $Set GUICtrlSetState($Label, $GUI_SHOW) For $i = 1 To $Count $Set = Int($i * 100 / $Count ) GUICtrlSetPos($Label, 8, 30, $i, 17) ConsoleWrite("$ProgressSet: " & $Set & @CR) GUICtrlSetData($Progress, $Set) Sleep(10) Next Exit EndSwitch WEnd
MyEarth Posted December 6, 2014 Author Posted December 6, 2014 Why did you make $Count = $width? Isn't so easy... $Count = number of items i need to process, can be 5, 10, 400 or 1.000 who knows but the progress percentage is based on that count, i can't make $Count = $width but for me was obv
mikell Posted December 6, 2014 Posted December 6, 2014 It was not obvious in your first post You will need a 2nd loop for the smoothness #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> $Count = 50 $width = 300 $hGUI = GUICreate("", 325, 72, -1, -1) $Progress = GUICtrlCreateProgress(8, 8, $width, 17, $PBS_SMOOTH) $Label = GUICtrlCreateLabel("", 8, 30, 1, 17) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetState(-1, $GUI_HIDE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUICtrlSetState($Label, $GUI_SHOW) For $i = 1 To $Count $Set = Int($i * 100 / $Count ) ConsoleWrite("$ProgressSet: " & $Set & @CR) GUICtrlSetData($Progress, $Set) For $j = 1 to $width/$Count GUICtrlSetPos($Label, 8, 30, $Set*($width/100)+$j-($width/$Count), 17) Sleep(20) Next ; Sleep(100) ; smoothness Next Exit EndSwitch WEnd WEnd
MyEarth Posted December 6, 2014 Author Posted December 6, 2014 For me was Thanks mikell, i'll check it out and if i have another question about it i'll let you know
mikell Posted December 6, 2014 Posted December 6, 2014 If your purpose is to use the label instead of the progress, the calculation is simpler #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> $Count = 50 $width = 300 $ratio = $width/$Count $hGUI = GUICreate("", 325, 72, -1, -1) $Progress = GUICtrlCreateProgress(8, 8, $width, 17, $PBS_SMOOTH) $Label = GUICtrlCreateLabel("", 8, 30, 1, 17) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetState(-1, $GUI_HIDE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUICtrlSetState($Label, $GUI_SHOW) For $i = 1 To $Count ; $Set = Int($i * 100 / $Count ) ; ConsoleWrite("$ProgressSet: " & $Set & @CR) ; GUICtrlSetData($Progress, $Set) For $j = 1 to $ratio ; GUICtrlSetPos($Label, 8, 30, $Set*($width/100)+$j-($width/$Count), 17) GUICtrlSetPos($Label, 8, 30, ($i-1)*$ratio+$j, 17) Sleep(20) Next ; Sleep(100) ; smoothness Next Exit EndSwitch WEnd
MyEarth Posted December 7, 2014 Author Posted December 7, 2014 (edited) I was thinking, instead of use the second For-Next ( For $j = 1 to $ratio ) is possible to use AdlibRegister? So i don't have a Sleep(20) in the main loop and the label-progress is a non blocking function. If is not possible i'll use the 2 loops solution. Thanks Edited December 7, 2014 by MyEarth
Solution mikell Posted December 7, 2014 Solution Posted December 7, 2014 (edited) It's possible The 'close' gui button can work while the label is progressing, this shows that updating is non blocking expandcollapse popup#include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> $Count = 600 $width = 300 $ratio = $width/$Count $progress = 0 $hGUI = GUICreate("", 325, 72, -1, -1) $Label = GUICtrlCreateLabel("", 8, 30, 0, 17) GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE If $progress = 0 Then Adlibregister("_update", 20) $progress = 1 Else Exit EndIf EndSwitch WEnd Func _update() Local Static $i = 0, $j = 0 If $j = 0 Then $i += 1 $j += 1 GUICtrlSetPos($Label, 8, 30, ($i-1)*$ratio+$j, 17) ConsoleWrite("$i = " & $i & " $j = " & $j & @CR) If $j >= $ratio Then $j = 0 If $i = $Count Then AdlibUnregister("_update") EndIf EndFunc Edited December 7, 2014 by mikell
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now