Jump to content

[Sleep] GuiGetMsg + Loop


eHrgo
 Share

Recommended Posts

Hi guys,

My problem is quit simple: I want to repeat a function every 10secs, I have a close button to stop that program at anytime..

Thos doesn't work:

$Close = GuiCtrlCreateButton.....

While GuiGetMsg() not $Close
...Whatever Function
Sleep (10000)
Wend
oÝ÷ Ù«­¢+Ø(ÀÌØí
±½ÍôÕ¥
Ñɱ
ÉÑ    ÕÑѽ¸¸¸¸¸¸()¼(¸¸¹]¡ÑÙÈչѥ½¸)M±À ÄÀÀÀÀ¤)U¹Ñ¥°Õ¥Ñ5Í ¤ôÀÌØí
±½Í(

I know this question has been asked a thousand time but i didn't understand how to easily solve it ... We can break with hotkeys at anytime, why can't we with GuiGetMsg?

Thanks

Sorry for my Bad English.
Link to comment
Share on other sites

I don't know if this answers your question, but the program probably will not close because, in the loops it only checks either at the beginning (while loop) or at the end (do-until loop), so there is a very small chance that it is checking for the button to be pressed exactly when you are pressing it... (same for other controls that you are looking for being pressed)

What goes around comes around... Payback's a bitch.

Link to comment
Share on other sites

  • Moderators

You may want to look at TimerInit()/TimerDiff() for your time periods rather than sleep.

Dim $nTimer = TimerInit()
While GuiGetMsg() <> $Close
    If TimerDiff($nTimer) / 1000 >= 10 Then
        ;.... whatever function // Keep in mind, that while in this function, GUIGetMsg() isn't going to work.
        $nTimer = TimerInit()
    EndIf
Wend

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hum .... I still have a problem:

I have now that:

$Timer10 = TimerInit()
While GuiGetMsg() <> $close
    GUISetState (@SW_SHOW) 
        If TimerDiff($Timer10) >= 10000 Then    
        Call ('GetPoints')
            $Timer10 = TimerInit()
        EndIf
    Wend
oÝ÷ Ø­jz-êÁºÛhÚ&Èe§¶+m¡Ú0«^½êÚrب^*kzË"´kçZºÚ"µÍÚ[HÝZQÙ]ÙÊ
H   ÉÝÈ  ÌÍØÛÜÙHÔ ÌÍÔÝ]

But it obviously don't work ... how can i do that?

Thanks a lot

Sorry for my Bad English.
Link to comment
Share on other sites

#include <GUIConstants.au3>
Dim $Gui_main = GUICreate("woof",150,100,-1,-1)
Dim $btn = GUICtrlCreateButton ( "Bark", 45,30,50)
Dim $enable = 1
GUISetState (@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $btn
            If $enable = 1 then
                AdlibEnable("woot",1000)
                $enable = 0
            Else
                AdlibDisable()
                $enable = 1
            EndIf
    EndSelect
WEnd
Func woot()
    ConsoleWrite("BLAH BLAH" & @CRLF)
EndFunc

Edited by Sykeo
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...