marfdaman Posted May 1, 2006 Share Posted May 1, 2006 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!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Link to comment Share on other sites More sharing options...
Developers Jos Posted May 1, 2006 Developers Share Posted May 1, 2006 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" ) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
marfdaman Posted May 2, 2006 Author Share Posted May 2, 2006 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!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 2, 2006 Moderators Share Posted May 2, 2006 (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 . Edit: Misplaced Code tag Edited May 2, 2006 by SmOke_N 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. Link to comment Share on other sites More sharing options...
marfdaman Posted May 2, 2006 Author Share Posted May 2, 2006 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. Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Link to comment Share on other sites More sharing options...
Developers Jos Posted May 2, 2006 Developers Share Posted May 2, 2006 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. 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 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
marfdaman Posted May 2, 2006 Author Share Posted May 2, 2006 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 ; 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!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Link to comment Share on other sites More sharing options...
Developers Jos Posted May 2, 2006 Developers Share Posted May 2, 2006 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 ; 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... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
marfdaman Posted May 2, 2006 Author Share Posted May 2, 2006 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!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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