poppe Posted February 20, 2012 Share Posted February 20, 2012 Hello I'm writing a code that automates the installation of a specifc software. During the installation process i need a separate window to show the progress with a timer. My test code: _Timer() ControlSend("My Application", "", "[CLASS:NewButton; INSTANCE:1]", "{ENTER}") Exit Func _Timer() ProgressOn("Progress Meter", "Increments every second", "0 percent") For $i = 10 To 100 Step 10 Sleep(1000) ProgressSet($i, $i & " percent") Next ProgressSet(100, "Done", "Complete") Sleep(500) ProgressOff() EndFunc ;==>_Main The Timer will start running, but the ControlSend will not happen until the timer has ran out. I need the timer to start on the background, and the main code to progress normally at the same time, so it can install the software. How can i run the timer as a separate process? Link to comment Share on other sites More sharing options...
AlmarM Posted February 20, 2012 Share Posted February 20, 2012 Sleep pauses the whole script.Take a look at the TimerInit and TimerDiff functions. Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
poppe Posted February 21, 2012 Author Share Posted February 21, 2012 (edited) Hi and thanks for the reply Even if i don't use sleep, the program hangs in the IF loop. It will wait until the IF has stopped executing, and proceed only after that. How can i run the progressbar function as a different process, so it does not interrupt the installation process? I would like the attached code to run during the installation process. If I know the installation takes for example 500 seconds, so i could pre-set it to 500. #include <Guiconstants.au3> Local $progressbar Local $i = 0 Sleep(500) GUICreate("babab", 180, 50) $progressbar = GUICtrlCreateProgress(10, 15, 160, 20) $label = Guictrlcreatelabel("",10,18,160,20,0x01) Guictrlsetbkcolor(-1, $GUI_BKCOLOR_TRANSPARENT) GUISetState() While Guigetmsg() <> -3 $i = $i + 1 GUICtrlSetData($progressbar, $i) GUICtrlSetData($label,$i) Sleep(20) If $i = 100 Then $i = 0 WEnd GUIDelete() Edited February 21, 2012 by poppe Link to comment Share on other sites More sharing options...
AlmarM Posted February 21, 2012 Share Posted February 21, 2012 (edited) Take a look at this. #include <Math.au3> Global $iTimer = TimerInit() Global $iUpdateDelay = 1000 ; 1 sec Global $hWnd = GUICreate("Test") Global $hProgress = GUICtrlCreateProgress(10, 10, 200, 20) GUISetState() While 1 Switch GUIGetMsg() Case -3 Exit EndSwitch If (TimerDiff($iTimer) >= $iUpdateDelay) Then $iTimer = TimerInit() $iPercentage = GUICtrlRead($hProgress) If ($iPercentage < 100) Then GUICtrlSetData($hProgress, _Min($iPercentage + 10, 100)) EndIf EndIf WEnd ; the _Min isn't really necessary in this sample. ; it's just a safety check if you are using other values for updating the progessbar Edited February 21, 2012 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
poppe Posted February 22, 2012 Author Share Posted February 22, 2012 OK thanks. I understand how your code works, but i don't understand how i can run it as a separate process. I have the following style code, that installs my application. Sleep is used to wait until the setup handles files, and then shows the next window on screen. This way the enter is sent to proper window. If Not ShellExecute("setup.exe") Then MsgBox(48, "My application", "Could not launch setup.") Exit EndIf Sleep (10000) ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:1]", "{ENTER}") Sleep (10000) ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:2]", "{ENTER}") Sleep (10000) WinActivate("My application - locales","") Sleep (10000) ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:2]", "{ENTER}") Where should i input your code, so the progressbar shows at the same time the installation proceeds ? Link to comment Share on other sites More sharing options...
AlmarM Posted February 22, 2012 Share Posted February 22, 2012 Let me get this straight. You want one application to automate an installation and one application that shows a progress bar? Why don't you combine those two in one script? Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
poppe Posted February 22, 2012 Author Share Posted February 22, 2012 Hi Yes. That is what i am trying to accomplish. I'm trying to combine your script with mine, and don't know how to do it. Link to comment Share on other sites More sharing options...
AlmarM Posted February 22, 2012 Share Posted February 22, 2012 You don't need a whole new script / process for creating another Window in which you can show a progress bar. You can simply create another GUI window and show the progress there. Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
poppe Posted February 23, 2012 Author Share Posted February 23, 2012 Hello In the following code i create the GUI for the progress bar: #include <Math.au3> Global $iTimer = TimerInit() Global $iUpdateDelay = 1000 ; 1 sec Global $hWnd = GUICreate("Test") Global $hProgress = GUICtrlCreateProgress(-1, -1, 500, 20) GUISetState(@SW_SHOW, $hWnd) While 1 Switch GUIGetMsg() Case -3 Exit EndSwitch If (TimerDiff($iTimer) >= $iUpdateDelay) Then $iTimer = TimerInit() $iPercentage = GUICtrlRead($hProgress) If ($iPercentage < 100) Then GUICtrlSetData($hProgress, $iPercentage + 1) EndIf EndIf WEnd The code itself is not finished yet, but shows the general idea. My application installation code: If Not ShellExecute("setup.exe") Then MsgBox(48, "My application", "Could not launch setup.") Exit EndIf Sleep (10000) ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:1]", "{ENTER}") Sleep (10000) ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:2]", "{ENTER}") Sleep (10000) WinActivate("My application - locales","") Sleep (10000) ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:2]", "{ENTER}") When the progress bar GUI window is created, it will hang in the While loop, and never progress further. If i just paste the second code after it, it will never get executed. Installing my application takes 50 seconds, so i can preset the progress bar to 50 seconds also and it will match. How to combine the two codes? Link to comment Share on other sites More sharing options...
AlmarM Posted February 23, 2012 Share Posted February 23, 2012 (edited) You could do something like this: Global $hWnd = GUICreate("", 300, 40) Global $hProgress = GUICtrlCreateProgress(10, 10, 280, 20) GUISetState() If (Not ShellExecute("setup.exe")) Then Exit MsgBox(48, "My application", "Could not launch setup.") EndIf GUICtrlSetData($hProgress, 20) Sleep (10000) ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:1]", "{ENTER}") GUICtrlSetData($hProgress, 40) Sleep (10000) ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:2]", "{ENTER}") GUICtrlSetData($hProgress, 60) Sleep (10000) WinActivate("My application - locales","") GUICtrlSetData($hProgress, 80) Sleep (10000) ControlSend("My application", "", "[CLASS:TNewButton; INSTANCE:2]", "{ENTER}") GUICtrlSetData($hProgress, 100) Sleep (10000) While 1 Switch GUIGetMsg() Case -3 Exit EndSwitch WEnd Edited February 23, 2012 by AlmarM poppe 1 Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
poppe Posted February 23, 2012 Author Share Posted February 23, 2012 (edited) Thank you! Now i can create it as it should be. Edited February 23, 2012 by poppe Link to comment Share on other sites More sharing options...
AlmarM Posted February 23, 2012 Share Posted February 23, 2012 Good luck! Come back whenever you need something. Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
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