Javik Posted March 6, 2012 Share Posted March 6, 2012 (edited) (This is a noobish question for GUI event monitoring.) Although this is from the example program for GUIGetMsg(), and it works, it seems like there is a serious problem. While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE MsgBox(0, "", "Dialog was closed") Exit Case $msg = $GUI_EVENT_MINIMIZE MsgBox(0, "", "Dialog minimized", 2) Case $msg = $GUI_EVENT_MAXIMIZE MsgBox(0, "", "Dialog restored", 2) Case $msg = $button_1 MsgBox(0, "Default button clicked", "Radio " & $radioval1) Case $msg >= $radio_1 And $msg <= $radio_3 $radioval1 = $msg - $radio_1 EndSelect WEnd If there is no GUI activity, the script is basically an infinite loop that runs with no delay. While 1 $msg = GUIGetMsg() WEnd Yet the task manager CPU usage does not jump to 100% when running the program. That seems... odd. It seems like the program design should be more event driven, so that if nothing is happening the program will sleep. Though apparently there is no such thing as EventWait until GUIGetMsg() $msg = GUIGetMsg() [. . . code goes here to process event . . .] EndEventWait Is this really the normal programming practice for Windows GUI event loops? It just seems wrong to be using an infinite loop with no idle-time release mechanism. Edited March 6, 2012 by Javik Link to comment Share on other sites More sharing options...
Developers Jos Posted March 6, 2012 Developers Share Posted March 6, 2012 Have you read the helpfile page about "GUI Concept"? 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...
Javik Posted March 6, 2012 Author Share Posted March 6, 2012 Have you read the helpfile page about "GUI Concept"?Oh puh-leaze, nobody reads manuals. We arrive here with just a vague idea of what we want to do, and hope the specific helpfiles and copied example scripts we're searching for, will provide enough detail to make our hackery work.Thanks for the guidance. Link to comment Share on other sites More sharing options...
Developers Jos Posted March 6, 2012 Developers Share Posted March 6, 2012 Your question was valid and well formulated, but I just had the impression you hadn't read that page yet and believe is gives a good explanations of the fundamentals. Don't hesitate to ask when things aren't clear yet. 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...
Javik Posted March 6, 2012 Author Share Posted March 6, 2012 (edited) (EDIT: I should just read the help files more thoroughly.)GUIGetMessageRemarksThis function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU. Edited March 6, 2012 by Javik Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 6, 2012 Moderators Share Posted March 6, 2012 Javik,I assume there must be more going on in the background, either in how the script is compiled or how Windows runs the codeSo obviously you did not read the page to which Jos pointed you? "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."If you do not use GUIGetMsg, e.g. in an OnEvent idle loop, you do need a Sleep(10) in there. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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