Jump to content
Sign in to follow this  
panlatv

Better to way to use a GUI and normal fonction in the same time

Recommended Posts

Hello,

And sorry for my bad english.

I don't want to stress the cpu, but i have a fonction to check all the time in a "GUI loop".

So, what it's the better way to do this?

Exemples with a GUI and a timer fonction, what it's the better way?

- exemple 1:

; >>> GUI
GUICreate("exemple 1",200,200)
$start=GUICtrlCreateButton ("Start", 5,5,42,24)
$stop=GUICtrlCreateButton ("Stop", 5,55,42,24)
GUISetState (@SW_SHOW)

$time = TimerInit()

; >>> Loop
While 1
       if TimerDiff($time)>2000 then msgbox (0,"Time","It's time !!!",5)
       $msg = GUIGetMsg()
       Select
       case $msg = $start
               msgbox (0,"Start","hello")
       case $msg = $stop
               msgbox (0,"Stop","finish")
       case $msg = $GUI_EVENT_CLOSE
               exitloop
       EndSelect    
Wend
Exit

- exemple 2:

; >>> GUI
GUICreate("exemple 2",200,200)
$start=GUICtrlCreateButton ("Start", 5,5,42,24)
$stop=GUICtrlCreateButton ("Stop", 5,55,42,24)
GUISetState (@SW_SHOW)

$time = TimerInit()

; >>> Loop
While 1
       $msg = GUIGetMsg()
       Select
       case $msg = $start
               msgbox (0,"Start","hello")
       case $msg = $stop
               msgbox (0,"Stop","finish")
       case $msg = $GUI_EVENT_CLOSE
               exitloop
       case else
               if TimerDiff($time)>2000 then msgbox (0,"Time","It's time !!!",5)    
       EndSelect    
Wend
Exit

Other way?

Thank you :)

Share this post


Link to post
Share on other sites

Thank for your help

Sleep(2000)

????

8)

I don't think so, the help of autoit, say that a "sleep" in a "GUI loop" can stress the cpu or cause the GUI to become unresponsive .

autoit help:

Do not put a manual sleep in the loop for fear of stressing the CPU - this will only cause the GUI to become unresponsive.

(and it's right) Edited by panlatv

Share this post


Link to post
Share on other sites

Read it again

The general layout of MessageLoop code is:

While 1

$msg = GUIGetMsg()

...

...

WEnd

Usually a tight loop like the one shown would send the CPU to 100% - fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting. Do not put a manual sleep in the loop for fear of stressing the CPU - this will only cause the GUI to become unresponsive.

The most important part

"fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting."

8)

Edited by Valuater

Share this post


Link to post
Share on other sites

Read it again

The general layout of MessageLoop code is:

While 1

$msg = GUIGetMsg()

...

...

WEnd

Usually a tight loop like the one shown would send the CPU to 100% - fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting. Do not put a manual sleep in the loop for fear of stressing the CPU - this will only cause the GUI to become unresponsive.

The most important part

"fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting."

8)

ok thank you, i understand now.

But, my exemple can't use a sleep fonction, in reality, my program is a GUI for videolan player. You can record the television (DVB t), and my timer fonction check if it's time to recording something. So if i put a sleep fonction, i will lost some "recording start".

Share this post


Link to post
Share on other sites

Maybe take a look at

AdlibEnable()

8)

Woo!! perfect fonction, thanks a lot :)

edit: How can i put "resolu" in the title of the topic? ^_^ thank you

Edited by panlatv

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  

×
×
  • Create New...