Sign in to follow this  
Followers 0
MrDelta1

progress bar doesn't stop looping

2 posts in this topic

Hi guys I am new at autoit.

To learn the basics I have created a script. With the script you can play easily flash games in a window. (not that usefull but it is just to learn the basics)

Now comes the problem....

If you open the script you wil see that the progress bar is not stopping looping and that is not good.

I wan't that the program starts up and that the progress bar loads and then just stop by the 100 %

And also if i load a game that he start again with loading from 0 to 100.

That s problem 1

problem 2 is that I somethimes must push three four times on a button before it work.

Can u help me :)

thanks alot.

here is the script.

;#NoTrayIcon
#include <GuiConstants.au3>
$basswd = InputBox("Security Check", "Enter your password.", "", "*")
if $basswd = "" Then
    MsgBox (0,"","Acces Granted")
Else
    Exit
EndIf
GUICreate ("Free Rider in Window", 600,500 )
GUISetFont(10 , 400, -1, "mS sans sherrif")
$ie = ObjCreate("Shell.Explorer.2"); create the, explorer object.

$Breaktime = GUICtrlCreateObj($IE, -1, -1, 500, 400); create the, embeded, object control.
; set the text in a variable called html.
$html = "about:Klik op beginnen om Free Rider te starten :-)BELANGRIJK: Dit progamma heeft internetverbinding nodig om te werken dus blokkeer het internet niet.                            v1.0 "& @CR
GuiCtrlCreatePic("http://www.freewebs.com/appelhead/freerider.bmp",300,300, 169,68)

$iE.navigate ( $html); navigate the explorer object to the html variable, ( known as about ).
$BrkStart = GUICtrlCreateButton("&Beginnen", 510,25, 80, 25)
$BrkEnd = GUICtrlCreateButton("&Stoppen", 510, 50, 80, 25)
$BrkEnd2 = GUICtrlCreateButton("&Eigen url", 510, 75, 80, 25)

$filemenu = GuiCtrlCreateMenu ("File")
$fileitem = GuiCtrlCreateMenuitem ("Open...",$filemenu)
$recentfilesmenu = GuiCtrlCreateMenu ("Recent Files",$filemenu)
$separator1 = GuiCtrlCreateMenuitem ("",$filemenu)
$exititem = GuiCtrlCreateMenuitem ("Exit",$filemenu)
$helpmenu = GuiCtrlCreateMenu ("?")
$gamemenu = GuiCtrlCreateMenu ("Andere Games")
$aboutitem = GuiCtrlCreateMenuitem ("About",$helpmenu)
$infoitem = GuiCtrlCreateMenuitem ("help",$helpmenu)
$game2 = GuiCtrlCreateMenuitem ("Fultime Killer *shooting game*",$gamemenu)
$game3 = GuiCtrlCreateMenuitem ("Free Rider *free riden :D*",$gamemenu)
$game4 = GuiCtrlCreateMenuitem ("Sword And Sandals* rpg*",$gamemenu)
$game5 = GuiCtrlCreateMenuitem ("Game2",$gamemenu)
$game6 = GuiCtrlCreateMenuitem ("Game2",$gamemenu)

$progressbar1 = GUICtrlCreateProgress (0,400,400,20,$PBS_SMOOTH)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($progressbar1), "wstr", "", "wstr", "")
$button = GUICtrlCreateButton ("Start",0,450,70,20)

GUISetState ()

$wait = 20; wait 20ms for next progressstep
$s = 0; progressbar-saveposition



GuiSetState()

GUISetState()

;

While 1; start loop, so the script continues and does not exit.
    do
$msg = GUIGetMsg()
If $msg = $basswd Then
    GUICtrlSetData ($button,"Staart")
    For $i = $s To 100

    $m = GUIGetMsg ()

    If $m = -3 Then ExitLoop
If $i = 100 Then ExitLoop
   
    If $m = $button Then
      GUICtrlSetData ($button,"Next")
      $s = $i;save the current bar-position to $s
      ExitLoop
    Else
        $s=0
      GUICtrlSetData ($progressbar1,$i)
    Sleep($wait)
    EndIf
    Next
    if $i >100 then
;     $s=0
        GUICtrlSetData ($button,"Start")
    endif
EndIf
until $msg = $GUI_EVENT_CLOSE
    
    $msg = GUIGetMsg(); listen for a message.
    
    if $msg = $game2 then 
        $ie.navigate ('http://83.149.121.2/2/shoot2.swf') 
        Sleep (3111)
    EndIf
    if $msg = $game4 then 
        $ie.navigate ('http://83.149.121.2/2/swordsandsandals2.swf')
        Sleep (1111)
        EndIf
    If $msg = $GUI_EVENT_CLOSE Or $msg = $BrkEnd Then; if exit is pressed, then exit the script.
        Exit
    EndIf
    If $msg = $BrkEnd2 Then; if exit is pressed, then exit the script.
    $eigenurl = InputBox("Vul in", "Vul de site url in.")
        $ie.navigate ($eigenurl)

    EndIf
    
    If $msg = $BrkStart Then; if this button is pushed, we navigate the object to the game site.
        $ie.navigate ('http://www.spele.nl/spelehost2/2/free_rider.swf') 
        sleep(4000)
EndIf
    

    $msg = GUIGetMsg()
    

    Select
ExitLoop
        
        Case $msg = $fileitem
            $file = FileOpenDialog("Open bestand",@DesktopCommonDir,"All (*.*)")
            If @error <> 1 Then GuiCtrlCreateMenuItem ($file,$recentfilesmenu)
        $B_oIE1.navigate ($file) 
        Case $msg = $exititem
            ExitLoop
        

        Case $msg = $aboutitem
            Msgbox(0,"About","GUI Menu Test")
    EndSelect
WEnd

GUIDelete()

Exit










$progressbar1 = GUICtrlCreateProgress (10,10,200,20,$PBS_SMOOTH)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($progressbar1), "wstr", "", "wstr", "")
$button = GUICtrlCreateButton ("Start",75,70,70,20)

GUISetState ()

$wait = 20; wait 20ms for next progressstep
$s = 0; progressbar-saveposition
do
$msg = GUIGetMsg()
If $msg = $basswd Then
    GUICtrlSetData ($button,"Start")
    For $i = $s To 100

    $m = GUIGetMsg ()
   
    If $m = -3 Then ExitLoop
   
    If $m = $button Then
      GUICtrlSetData ($button,"Next")
      $s = $i;save the current bar-position to $s
      ExitLoop
    Else
        $s=0
      GUICtrlSetData ($progressbar1,$i)
    Sleep($wait)
    EndIf
    Next
    if $i >100 then
;     $s=0
        GUICtrlSetData ($button,"Start")
    endif
EndIf
until $msg = $GUI_EVENT_CLOSE

Share this post


Link to post
Share on other sites



If you open the script you wil see that the progress bar is not stopping looping and that is not good.

I wan't that the program starts up and that the progress bar loads and then just stop by the 100 %

And also if i load a game that he start again with loading from 0 to 100.

That s problem 1

problem 2 is that I somethimes must push three four times on a button before it work.

The following demo illustrates the following:

1. Keep the progress in a variable and use an If/Then test to only update the progress bar if < 100.

2. Use of GuiOnEventMode to keep the script from being trapped in a GuiGetMsg() loop. Event mode is usually more responsive.

#include <GuiConstants.au3>

Opt("GuiOnEventMode", 1)

Global $RunFlag = False, $Progress = 0

GUICreate("Free Rider in Window", 600, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$progressbar1 = GUICtrlCreateProgress(0, 400, 400, 20, $PBS_SMOOTH)
$button = GUICtrlCreateButton("Start", 0, 450, 70, 20)
GUICtrlSetOnEvent(-1, "_StartStop")
GUISetState()

While 1
    Sleep(20)
    If $RunFlag Then _UpdateProgress()
WEnd

Func _StartStop()
    $RunFlag = Not $RunFlag
    If $RunFlag Then
        GUICtrlSetData($button, "Stop")
    Else
        GUICtrlSetData($button, "Start")
    EndIf
EndFunc   ;==>_StartStop

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Func _UpdateProgress()
    If $Progress < 100 Then
        $Progress += 1
        GUICtrlSetData($progressbar1, $Progress)
    EndIf
EndFunc   ;==>_UpdateProgress

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0