Sign in to follow this  
Followers 0
jimmyjmmy

why sleep so long

10 posts in this topic

#1 ·  Posted (edited)

Hi,

I am trying to understand Gui. So I played with the undermentioned script. The script below have only one sleep function. Without the sleep fuction, everything goes on smoothly but I dont understand why when I add that sleep statement, I dont see any msg pop out after I pressed the ok button. I pressed the ok button many times and it seems that the pop out message will pop out but randomly.

I thought sleep function will only cause the system to delay but the script below seems to delay indefinately.

-----------script ----------------------------

#include <GUIConstants.au3>

GUICreate("My Controller") ; will create a dialog box that when displayed is centered

GUICtrlCreateLabel("Hello world! How are you?", 30, 10)

GUISetState (@SW_SHOW) ; will display an empty dialog box

$okbutton = GUICtrlCreateButton ("Playback", 10, 30, 120, 40)

while 1

$msg = GUIGetMsg ()

Select

Case $msg = $okbutton

MsgBox(0, "GUI Event", "You pressed OK!")

EndSelect

if $msg = $okbutton then

msgbox ( 1 ,"under construction", "Still under construction")

EndIf

sleep (1000)

WEnd

Edited by jimmyjmmy

Share this post


Link to post
Share on other sites



Hi,

I am trying to understand Gui. So I played with the undermentioned script. The script below have only one sleep function. Without the sleep fuction, everything goes on smoothly but I dont understand why when I add that sleep statement, I dont see any msg pop out after I pressed the ok button. I pressed the ok button many times and it seems that the pop out message will pop out but randomly.

I thought sleep function will only cause the system to delay but the script below seems to delay indefinately.

-----------script ----------------------------

#include <GUIConstants.au3>

GUICreate("My Controller") ; will create a dialog box that when displayed is centered

GUICtrlCreateLabel("Hello world! How are you?", 30, 10)

GUISetState (@SW_SHOW) ; will display an empty dialog box

$okbutton = GUICtrlCreateButton ("Playback", 10, 30, 120, 40)

while 1

$msg = GUIGetMsg ()

Select

Case $msg = $okbutton

MsgBox(0, "GUI Event", "You pressed OK!")

EndSelect

if $msg = $okbutton then

msgbox ( 1 ,"under construction", "Still under construction")

EndIf

sleep (1000)

WEnd

My first answer is that your setting 2 things to happen when $okbutton is pressed :shocked:

Share this post


Link to post
Share on other sites

Hi,

I am trying to understand Gui. So I played with the undermentioned script. The script below have only one sleep function. Without the sleep fuction, everything goes on smoothly but I dont understand why when I add that sleep statement, I dont see any msg pop out after I pressed the ok button. I pressed the ok button many times and it seems that the pop out message will pop out but randomly.

I thought sleep function will only cause the system to delay but the script below seems to delay indefinately.

-----------script ----------------------------

#include <GUIConstants.au3>

GUICreate("My Controller") ; will create a dialog box that when displayed is centered

GUICtrlCreateLabel("Hello world! How are you?", 30, 10)

GUISetState (@SW_SHOW) ; will display an empty dialog box

$okbutton = GUICtrlCreateButton ("Playback", 10, 30, 120, 40)

while 1

$msg = GUIGetMsg ()

Select

Case $msg = $okbutton

MsgBox(0, "GUI Event", "You pressed OK!")

EndSelect

if $msg = $okbutton then

msgbox ( 1 ,"under construction", "Still under construction")

EndIf

sleep (1000)

WEnd

You don't need the sleep statement. The GUIGetMsg function has a sleep built into it (see the help file). The reason your code doesn't work, is that it's sleeping when the click is occuring and is missed by GUIGetMsg.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi,

I am trying to understand Gui. So I played with the undermentioned script. The script below have only one sleep function. Without the sleep fuction, everything goes on smoothly but I dont understand why when I add that sleep statement, I dont see any msg pop out after I pressed the ok button. I pressed the ok button many times and it seems that the pop out message will pop out but randomly.

I thought sleep function will only cause the system to delay but the script below seems to delay indefinately.

-----------script ----------------------------

#include <GUIConstants.au3>

GUICreate("My Controller") ; will create a dialog box that when displayed is centered

GUICtrlCreateLabel("Hello world! How are you?", 30, 10)

GUISetState (@SW_SHOW) ; will display an empty dialog box

$okbutton = GUICtrlCreateButton ("Playback", 10, 30, 120, 40)

while 1

$msg = GUIGetMsg ()

Select

Case $msg = $okbutton

MsgBox(0, "GUI Event", "You pressed OK!")

EndSelect

if $msg = $okbutton then

msgbox ( 1 ,"under construction", "Still under construction")

EndIf

sleep (1000)

WEnd

Oh you dummies!

#include <GUIConstants.au3>

GUICreate("My Controller")  ; will create a dialog box that when displayed is centered
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton ("Playback", 10, 30, 120, 40) ;moved this up one line
GUISetState (@SW_SHOW)       ; will display an empty dialog box
while 1
$msg = GUIGetMsg ()
Select
Case $msg = $okbutton
MsgBox(0, "GUI Event", "You pressed OK!")
Msgbox ( 1 ,"under construction", "Still under construction") ; You also can add 16 (at flag) so you have a error sign or 48 for exclamation
;added next case for closing script and GUI with X-button (you know, as you close Firefox or IE)
Case $msg = $GUI_EVENT_CLOSE
Exit
EndSelect
;you need to end while loop with WEnd
WEnd
;you don't need IF, just put other stuff in Case, like I did

Not tested :shocked:.

i542

EDIT: Error in code.

Edited by i542

I can do signature me.

Share this post


Link to post
Share on other sites

The script below have only one sleep function. Without the sleep fuction, everything goes on smoothly but I dont understand why when I add that sleep statement, I dont see any msg pop out after I pressed the ok button. I pressed the ok button many times and it seems that the pop out message will pop out but randomly.

I thought sleep function will only cause the system to delay but the script below seems to delay indefinately.

Here is my first script in AutoIt v2 (now converted to v3)

MsgBox(0,"Hi","Hello World")
Sleep(20000) ;waits until user closes the box
;...oÝ÷ Ù.±ç­ç«®ÀºÚµ«­¢f­Æ¥+-¢,r¸©¶éí[azºÛh+)­ë,yÒÊ«º{aË®*mÊ°Y'$¢sÁ¨­ÛKrݱ©Ý¶§rí{Ü"bjZ nZ~׫ç«rݳ*.ç¶vئz­jëh×6MsgBox(0,"Hi","This will close in 5 seconds",5)

Got it?

i542


I can do signature me.

Share this post


Link to post
Share on other sites

Soime modifications and comments in your code..:shocked:

Func msgboxtimeout()
   GUICreate("My Controller") ; will create a dialog box that when displayed is centered
   GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
   ;;Better move this line belowe the buttonGUISetState (@SW_SHOW) ; will display an empty dialog box
   $okbutton = GUICtrlCreateButton ("Playback", 10, 30, 120, 40)
   GUISetState (@SW_SHOW) ; will display an empty dialog box
   ;;
   while 1
      ; Get windows messages
      $msg = GUIGetMsg ()
      Select
         Case $msg = $okbutton
            MsgBox(0, "GUI Event", "You pressed OK!")
      EndSelect
      ;; Why do this test again here?? It's the same test as Case $msg = $okbutton
      if $msg = $okbutton then
         msgbox ( 1 ,"under construction", "Still under construction")
      EndIf 
      ;If you sleep more than 250ms you will start loosing windows messages. As a click on the button.
      ; Windows is to blaim not AutoIt!
      ;After the latest release a sleep call is not needed in the message loop anymore as 
      ; it is taken care of by the script engine. Butt to make sure use a sleep(10)
      ;sleep (1000)
      Sleep(10)
   WEnd 
EndFunc

Share this post


Link to post
Share on other sites

Soime modifications and comments in your code.. :shocked:

Func msgboxtimeout()
   GUICreate("My Controller") ; will create a dialog box that when displayed is centered
   GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
   ;;Better move this line belowe the buttonGUISetState (@SW_SHOW) ; will display an empty dialog box
   $okbutton = GUICtrlCreateButton ("Playback", 10, 30, 120, 40)
   GUISetState (@SW_SHOW) ; will display an empty dialog box
   ;;
   while 1
      ; Get windows messages
      $msg = GUIGetMsg ()
      Select
         Case $msg = $okbutton
            MsgBox(0, "GUI Event", "You pressed OK!")
      EndSelect
      ;; Why do this test again here?? It's the same test as Case $msg = $okbutton
      if $msg = $okbutton then
         msgbox ( 1 ,"under construction", "Still under construction")
      EndIf 
      ;If you sleep more than 250ms you will start loosing windows messages. As a click on the button.
      ; Windows is to blaim not AutoIt!
      ;After the latest release a sleep call is not needed in the message loop anymore as 
      ; it is taken care of by the script engine. Butt to make sure use a sleep(10)
      ;sleep (1000)
      Sleep(10)
   WEnd 
EndFunc
what a heck is that?

i542


I can do signature me.

Share this post


Link to post
Share on other sites

I thought I would take a crack at it

#include <GUIConstants.au3>
Dim $var

GUICreate("My Controller") ; will create a dialog box that when displayed is centered
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
GUISetState (@SW_SHOW) ; will display an empty dialog box
$okbutton = GUICtrlCreateButton ("Playback", 10, 30, 120, 40)
while 1
$msg = GUIGetMsg ()
Select
Case $msg = $okbutton
MsgBox(0, "GUI Event", "You pressed OK!")
$var = 1
EndSelect

if $var = 1 then
msgbox ( 1 ,"under construction", "Still under construction")
$var =  0
EndIf 
sleep (10)

WEnd

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

You don't need the sleep statement. The GUIGetMsg function has a sleep built into it (see the help file). The reason your code doesn't work, is that it's sleeping when the click is occuring and is missed by GUIGetMsg.

Thank You all sooooo much PaulIA and everybody.

I spent some time thinking about what you said and now I understand.

So after sleeping until the time it began to sleep, which is very fast, I need to press the ok button so that GUIGetMsg will receive my click. Because the time is so fast between awake to going-to-sleep, its unlikely I am able to press the ok button between this awake time. So this exlain why if I press the ok button many times repeatedly, the msgbox do appear randomly. Am I right or am I imagining things.

Thanks

Share this post


Link to post
Share on other sites

Thank You all sooooo much PaulIA and everybody.

I spent some time thinking about what you said and now I understand.

So after sleeping until the time it began to sleep, which is very fast, I need to press the ok button so that GUIGetMsg will receive my click. Because the time is so fast between awake to going-to-sleep, its unlikely I am able to press the ok button between this awake time. So this exlain why if I press the ok button many times repeatedly, the msgbox do appear randomly. Am I right or am I imagining things.

Thanks

The longer the sleep the less chance you will have to press the OK button.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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