Chinasmoker Posted November 16, 2007 Posted November 16, 2007 (edited) I ve used MessageLoop Mode ever before,found it increased CPU load,so I learned oneventmode,and used much func ..endfunc to respond to GUI event ,but I dont understand what the while loop in the middle of the script putted,eg CODE#include <GUIConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $mainwindow = GUICreate("Hello World", 200, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlCreateLabel("Hello world! How are you?", 30, 10) $okbutton = GUICtrlCreateButton("OK", 70, 50, 60) GUICtrlSetOnEvent($okbutton, "OKButton") GUISetState(@SW_SHOW) While 1 Sleep(1000) ; Idle around------this,My question WEnd Func OKButton() ;Note: at this point @GUI_CTRLID would equal $okbutton, ;and @GUI_WINHANDLE would equal $mainwindow MsgBox(0, "GUI Event", "You pressed OK!") EndFunc Func CLOSEClicked() ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, ;and @GUI_WINHANDLE would equal $mainwindow MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...") Exit EndFunc Thanks Edited November 16, 2007 by Chinasmoker One is never too old to learn
PsaltyDS Posted November 16, 2007 Posted November 16, 2007 I ve used MessageLoop Mode ever before,found it increased CPU load,so I learned oneventmode,and used much func ..endfuncto respond to GUI event ,but I dont understand what the while loop in the middle of the script putted,egYou have to have a loop somewhere to keep the script alive. In most GuiOnEventMode scripts, where there are other things going on besides the GUI, a sleep of 1000 is much too long. Most of my scripts use Sleep(20) in a little While loop to keep the script alive, but responsive. 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
Chinasmoker Posted November 16, 2007 Author Posted November 16, 2007 You have to have a loop somewhere to keep the script alive. In most GuiOnEventMode scripts, where there are other things going on besides the GUI, a sleep of 1000 is much too long. Most of my scripts use Sleep(20) in a little While loop to keep the script alive, but responsive. I got it ,Thanks One is never too old to learn
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