Jump to content
Sign in to follow this  
Chinasmoker

oneventmode

Recommended Posts

Chinasmoker

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 by Chinasmoker

One is never too old to learn

Share this post


Link to post
Share on other sites
PsaltyDS

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

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.

:P


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

Share this post


Link to post
Share on other sites
Chinasmoker

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.

:P

I got it ,Thanks


One is never too old to learn

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  

×