jimmyjmmy Posted April 24, 2007 Share Posted April 24, 2007 (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 April 24, 2007 by jimmyjmmy Link to comment Share on other sites More sharing options...
BrettF Posted April 24, 2007 Share Posted April 24, 2007 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 centeredGUICtrlCreateLabel("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) WEndMy first answer is that your setting 2 things to happen when $okbutton is pressed Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
PaulIA Posted April 24, 2007 Share Posted April 24, 2007 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 centeredGUICtrlCreateLabel("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) WEndYou 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 Link to comment Share on other sites More sharing options...
i542 Posted April 24, 2007 Share Posted April 24, 2007 (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) WEndOh 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 . i542 EDIT: Error in code. Edited April 24, 2007 by i542 I can do signature me. Link to comment Share on other sites More sharing options...
i542 Posted April 24, 2007 Share Posted April 24, 2007 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ئzjëh×6MsgBox(0,"Hi","This will close in 5 seconds",5) Got it? i542 I can do signature me. Link to comment Share on other sites More sharing options...
Uten Posted April 24, 2007 Share Posted April 24, 2007 Soime modifications and comments in your code.. 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 Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
i542 Posted April 24, 2007 Share Posted April 24, 2007 Soime modifications and comments in your code.. 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 EndFuncwhat a heck is that? i542 I can do signature me. Link to comment Share on other sites More sharing options...
nitekram Posted April 24, 2007 Share Posted April 24, 2007 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 2¢ 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." 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 Link to comment Share on other sites More sharing options...
jimmyjmmy Posted April 25, 2007 Author Share Posted April 25, 2007 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 Link to comment Share on other sites More sharing options...
nitekram Posted April 25, 2007 Share Posted April 25, 2007 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.ThanksThe longer the sleep the less chance you will have to press the OK button. 2¢ 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." 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 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