Sign in to follow this  
Followers 0
marfdaman

Help A (as Of Yet) N00b Please

9 posts in this topic

Hi, I'll skip the usual stuff about being new to all this and desparately needing help etc...

So, I was working on this beautiful mp3 player, and when it was finished I noticed the CPU usage was an

average 40% (it's about 1200 lines long). So i decided to turn it into a OnEvent type of script so CPU might go down. However, now with all done, what happens is the following: the player starts it's splashscreen (ok), loads the main window (ok), then shows th exit popup and exits (not ok). Personally I think it's because i dont' use GUICtrlSetOnEvent correctly, and yes I have checked the help file.

Some hint as to why it shows this behaviour would be very much appreciated!


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites



Hi, I'll skip the usual stuff about being new to all this and desparately needing help etc...

So, I was working on this beautiful mp3 player, and when it was finished I noticed the CPU usage was an

average 40% (it's about 1200 lines long). So i decided to turn it into a OnEvent type of script so CPU might go down. However, now with all done, what happens is the following: the player starts it's splashscreen (ok), loads the main window (ok), then shows th exit popup and exits (not ok). Personally I think it's because i dont' use GUICtrlSetOnEvent correctly, and yes I have checked the help file.

Some hint as to why it shows this behaviour would be very much appreciated!

You are not getting an error ?

these type of statements don't look right:

GUICtrlSetOnEvent($volumeslider, _volumeslider($volume))

the function needs to be a string..... don't think parameters are supported ....

GUICtrlSetOnEvent ( controlID, "function" )


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

You are not getting an error ?

these type of statements don't look right:

GUICtrlSetOnEvent($volumeslider, _volumeslider($volume))

the function needs to be a string..... don't think parameters are supported ....

GUICtrlSetOnEvent ( controlID, "function" )

No I don't get any errors, but I already thought that the parameters in the functions might have been the problem, as I couldn't find any script in OnEventMode that used them. I guess I'll just stick to the Guigetmsg way then. Maybe this is something for the next version.

Thanks for your reply!


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

No I don't get any errors, but I already thought that the parameters in the functions might have been the problem, as I couldn't find any script in OnEventMode that used them. I guess I'll just stick to the Guigetmsg way then. Maybe this is something for the next version.

Thanks for your reply!

The only 2 issues you have run into, one being a biggy, is 1. You need to wrap the function in quotes like so:
GUICtrlSetOnEvent($volumeslider, "_volumeslider")
And 2. You cannot pass parameters this way GUICtrlSetOnEvent(), it can only be a Function call in which the function has no parameters.

Example:

Func _volumeslider()
Is correct with this example and
Func _volumeslider($Parameter = '')
Or
Func _volumeslider($Parameter)
Is incorrect.

There's ways around this (Parameters) if you truly must use OnEvent, but I like the good old GUIGetMsg() myself :think:.

Edit:

Misplaced Code tag

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

The only 2 issues you have run into, one being a biggy, is 1. You need to wrap the function in quotes like so:

GUICtrlSetOnEvent($volumeslider, "_volumeslider")
And 2. You cannot pass parameters this way GUICtrlSetOnEvent(), it can only be a Function call in which the function has no parameters.

Example:

Func _volumeslider()
Is correct with this example and
Func _volumeslider($Parameter = '')
Or
Func _volumeslider($Parameter)
Is incorrect.

There's ways around this (Parameters) if you truly must use OnEvent, but I like the good old GUIGetMsg() myself :(.

Edit:

Misplaced Code tag

Well it's only necessary if using this mode will really (as I think) lower the CPU usage. Otherwise I'll just use the one with GuiGetmsg, which now uses an average of 15% when playing music (still too much IMHO).

I am interested in the way around though, so if you could perhaps explain it to me, I would be grateful. :think:


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

Well it's only necessary if using this mode will really (as I think) lower the CPU usage. Otherwise I'll just use the one with GuiGetmsg, which now uses an average of 15% when playing music (still too much IMHO).

I am interested in the way around though, so if you could perhaps explain it to me, I would be grateful. :think:

To save cpu in a getmsg() loop you could do something like this:

While 1
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then ExitLoop
  ; Only perform the Select logic when a control is activated
   If $msg < 1 Then ContinueLoop
  ;
   Select        
      Case $msg =  .....
       ;

   EndSelect
WEnd

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

To save cpu in a getmsg() loop you could do something like this:

While 1
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then ExitLoop
 ; Only perform the Select logic when a control is activated
   If $msg < 1 Then ContinueLoop
 ;
   Select        
      Case $msg =  .....
      ;

   EndSelect
WEnd

First of all, I really like the way people on this forum treat each other.

That said, your suggestion gave me a very good idea :think: ; I decided to do this

While 1
    $msg = GUIGetMsg(1)
    $traymsg = TrayGetMsg()
    If $msg[0] <> 0 Then
        _guigetmessage()
    EndIf
    If $traymsg <> 0 Then
        _traymessage()
    EndIf
WEnd

and put what was originally in the while loop in a function called _guigetmessage. This decreased cpu usage from ~14% to ~5% :( (when playing, when idle it takes up 0%). I don't know if this is something everybody but me does, but if it isn't this is surily (spelled correctly?) worth the little time it takes to turn 98% of your loop into a function.

Thanks for your helping!!!


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

First of all, I really like the way people on this forum treat each other.

That said, your suggestion gave me a very good idea :think: ; I decided to do this

While 1
    $msg = GUIGetMsg(1)
    $traymsg = TrayGetMsg()
    If $msg[0] <> 0 Then
        _guigetmessage()
    EndIf
    If $traymsg <> 0 Then
        _traymessage()
    EndIf
WEnd

and put what was originally in the while loop in a function called _guigetmessage. This decreased cpu usage from ~14% to ~5% :( (when playing, when idle it takes up 0%). I don't know if this is something everybody but me does, but if it isn't this is surily (spelled correctly?) worth the little time it takes to turn 98% of your loop into a function.

Thanks for your helping!!!

I would use :

If $msg[0] > 0 Then
        _guigetmessage()
    EndIf

To avoid the tests being done on mouse movement......

veel plezier...


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I would use :

If $msg[0] > 0 Then
        _guigetmessage()
    EndIf

To avoid the tests being done on mouse movement......

veel plezier...

OK thanx, I didn't know mouse movements were also detected by GuiGetMsg().

Doesn't matter much though, as I built in a "hide" mode which I use practically use all the time.

Hij gebruikt als hij gecompiled is trouwens 0% CPU. Magnificent!


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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