Jump to content

GUIGetMsg .... Infinite event loop with no delay?


Javik
 Share

Recommended Posts

(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 by Javik
Link to comment
Share on other sites

Have you read the helpfile page about "GUI Concept"?

Oh puh-leaze, nobody reads manuals. :oops:

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

  • Developers

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

(EDIT: I should just read the help files more thoroughly.)

GUIGetMessage

Remarks

This function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU.

Edited by Javik
Link to comment
Share on other sites

  • Moderators

Javik,

I assume there must be more going on in the background, either in how the script is compiled or how Windows runs the code

So obviously you did not read the page to which Jos pointed you? :oops:

"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. :bye:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...