Jump to content

Refresh GUI or similar


blumi
 Share

Recommended Posts

I made a small GUI with a timer.

The timer starts with two digits (10) and goes down to 0.

If 0 is reached a software should be started.

I have the problem, when the counter starts from two digits and the numbers with one digit are shown there is a rest from the second digit still shown on the GUI.

How to remove that?

Posted Image

Here some code, if you need more, let me know.

; Show the GUI
GuiSetState ()
Timer()
While 1
$msg = GUIGetMsg()
Select
  Case $msg = $GUI_EVENT_CLOSE Or $msg = $ButtonExit
  Exit
  Case $msg = $infoitem
   MsgBox(0, $ScriptName, $CopyRight)
EndSelect
WEnd
GUIDelete()

Func Timer()
For $i=$timer To 0 Step -1
  Sleep(1000)
  GUISetFont (16, 400, 0, $font)
  GUICtrlCreateLabel ($i, $breite/2, $PosLabel)
  If ($i = 0) Then
   MsgBox(0, $ScriptName, "Start of the Software")
  EndIf
Next
EndFunc
Link to comment
Share on other sites

You're recreating the label everytime through the loop. You should be using GUICtrlSetData to change the label instead of making new ones.

; Show the GUI 
GuiSetState () 
Timer() 
While 1 
    $msg = GUIGetMsg() 
    Select 
       Case $msg = $GUI_EVENT_CLOSE Or $msg = $ButtonExit 
            Exit 
       Case $msg = $infoitem 
            MsgBox(0, $ScriptName, $CopyRight) 
    EndSelect 
WEnd 
GUIDelete() 
Func Timer() 
    For $i=$timer To 0 Step -1 Sleep(1000) 
       GUISetFont (16, 400, 0, $font)  
       GUICtrlSetData($Labelhandle, $i) ; Something like this 
    Next 
    MsgBox(0, $ScriptName, "Start of the Software") ; No need to check if $i is zero because when the loop ends, it's zero and you can show the msgbox after it ends. 
EndFunc
Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks for your help, now the conter works fine.

Detected another problem.

During my counter goes down nothing happens when I click on my Exit Button.

How can I realize that during the counter counts the exit button works and will abort the script?

Tried something like this, but does not work.

For $i=$timer To 0 Step -1
Sleep(1000)
GUICtrlSetData($LabelTimer, $i)
$msg = GUIGetMsg()
If ($msg = $ButtonExit) Then
Exit
EndIf

Next
Link to comment
Share on other sites

Here's something that I threw together to give you one idea of how you can do it. It uses AdLibRegister to call the timer function approximately once a second and counts down to zero. Once it reaches zero it unregisters the function and displays your message box. You will be able to interrupt this by pressing the Exit button which will exit the script completely. This isn't the only way to do it, but for a timer that's running in the background it's the easiest to get your head around without getting too fancy.

#include <GUIConstantsEx.au3>
; Show the GUI
$GUI = GUICreate("Test", 400, 400, -1, -1)
$Labelhandle = GUICtrlCreateLabel("10", 40, 40, 200, 200)
$ButtonExit = GUICtrlCreateButton("Exit", 20, 300)
GUICtrlSetFont($Labelhandle, 60, 600, 0, "Arial")
Global $I = 10
GUISetState()
AdlibRegister("Timer", 1000) ; this will call the function Timer once a second
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $ButtonExit
            Exit
;~      Case $msg = $infoitem
;~          MsgBox(0, $ScriptName, $CopyRight)
    EndSelect
WEnd
GUIDelete()
Func Timer()
    GUICtrlSetFont($Labelhandle, 60, 600, 0, "Arial")
    GUICtrlSetData($Labelhandle, $I) ; Something like this
    $I -= 1
    If $I = 0 Then
        MsgBox(0, @ScriptName, "Start of the Software")
        AdlibUnRegister("Timer") ; Once $I = 0 then unregister the function from the AdLib so it won't be called again.
;~      Add in other things in here that you want to have happen after the timer has run out
    EndIf
EndFunc   ;==>Timer

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...