Jump to content

Seeking clarity re methods for handling GUI Controls


timmy2
 Share

Recommended Posts

I have the impression that the traditional method for processing responses to a GUI is to assign variables to each GUICreateButton (or Pic) and then use Switch/Case/Endswitch to detect when any Control is clicked.  In the tutorials I've seen about Koda it appears to use this method, too.

While 1
    Global $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Pic2
            Call("verizon")
        Case $Pic3
            Call("skype")
        Case $PicExit
            Exit
    EndSwitch
WEnd

But in a few examples I've seen a script use a different method. The script always includes the following option near the top:

Opt("GUIOnEventMode", 1)

...and then, later, after creating each Control for the GUI, there's the function, GUICtrlSetOnEvent.  In these cases a very simple While/WEnd loop is used to wait for the user to respond. 

I happened to employ this second method in a recent script where I used "canned" controls (checkbox and buttons). Later in the same script I used the GuiCreatePic and Switch/Case/EndSwitch method because my GUI was all custom images. (I'm not sure if that's necessary, but it's what I've deduced.) The second GUI failed to respond to any mouse clicks, but eventually I figured out the cause was the GUIOnEvenMode being enabled at the top of the script.

This is when I realized I don't understand the reasoning behind choosing between these two methods. And I'm having no luck phrasing an appropriate search criterion. Is there an overview somewhere that explains the two methods and -- most importantly -- describes when each is appropriate?

Link to comment
Share on other sites

I guess your search didn't include the HELP file.  It even goes so far as to suggest when one would be better than the other.

https://www.autoitscript.com/autoit3/docs/guiref/GUIRef.htm

 

Edited by TheXman
Link to comment
Share on other sites

  • Developers
2 minutes ago, timmy2 said:

I did indeed search the HELP file but in my case the results were a haystack.

Not really when you simply use the TOC, select GUI Reference and then GUI Concept. ;)

Jos

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

1 hour ago, timmy2 said:

This is when I realized I don't understand the reasoning behind choosing between these two methods. And I'm having no luck phrasing an appropriate search criterion. Is there an overview somewhere that explains the two methods and -- most importantly -- describes when each is appropriate?

Your question was about event modes not controls.  Why would you search for GUI create when you want to know about GUI event modes. 

image.png.fee5b6481422d90c530af405d55aeb13.png

Link to comment
Share on other sites

1 hour ago, TheXman said:

Your question was about event modes not controls.  Why would you search for GUI create when you want to know about GUI event modes. 

How right you are, @TheXman, if only I had started out knowing the subject is "event modes" instead of "controls". People like me should not be allowed to ask questions until they know such everyday terminology.

GUICreate was the first function that both methods have in common, and when one is grasping for a term to start with it was reasonable if futile starting point.

Link to comment
Share on other sites

1 hour ago, Jos said:

Not really when you simply use the TOC, select GUI Reference and then GUI Concept. ;)

Jos

@jos, in this case the TOC would have been the best entry point. Not to excuse myself, but I'm just so accustomed to searching the forums and the HELP Index,  then following the breadcrumbs. This lesson learned. (in which case I always ask myself, "How many more are there?" :>)

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

×
×
  • Create New...