Gui Concept
GUI can be composed of one or moreWindowThese windows contain one or more controls. Gui relies on "event-driven" to implement interaction with users. For example, an action Like clicking a button triggers an event.ProgramWait for an event to occur when the event is idle. When an event is captured, perform related operations based on the event. You can guess that you are waiting for the postman at the door (sitting there until a letter is sent in). When the postman sends the letter, you need to read the letter and decide what to do next, this is the same as the GUI principle: you are waiting for the postman, while the GUI is waiting for the event,
Of course, you can also select other tasks when running gui (the Program Interface). For example, you can use GUI functions to create an automatically updated dynamic progress bar, other complex tasks can also be executed.
Gui controls
All users should have a good understanding of the controls. The components that can be clicked in the window or interact with others are a type of controls. Controls that can be created by autoit are of the following types (you must have seen them in other Windows programs ):
| Label |
Text Control |
| Button |
Button |
| Input |
Single-row edit box for text input |
| Edit |
Multi-line editing box for input text |
| Checkbox |
Box button to be selected or unselected |
| Radio |
Circle button (usually a few groups, only one of them can be activated/selected at a time) |
| Combo |
Combo box with a drop-down list |
| List |
List box |
| Date |
Date Selection |
| PIC |
Image |
| Icon |
Icon |
| SS |
Progress bar |
| Tab |
Label. Each scalar can contain a group of controls. |
| Updown |
Can be attached to an input control. |
| Avi |
Show clips in AVI format |
| Menu |
Menu at the top of the window |
| Contextmenu |
The menu that appears when you right-click a window |
| Treeview |
Similar to Windows Resource Manager (Tree View) |
| Slider |
Volume Control similar to Windows (slide) |
| Listview |
Controls that display information by column (List View) |
| Listviewitem |
Listview Control Project |
| Dummy |
Virtual User Control |
The following is a single-window GUI example, which contains many controls supported by autoit. We can see that autoit can indeed create a rich set of guis!
You can use functions such as guictrlcreate... to create a control. The function will returnControl ID. There are several precautions for the Control ID:
The Control ID is a positive number (that is, the number is greater than 0)
Each Control ID is unique (even if multiple Windows exist ).
The Control ID can be obtained through autoit window info.
Gui basic functions
The following are the functions that can be used to create a GUI. However, these are basic applications. If you are ready to create a more advanced GUI, there are other advanced functions.
| Function |
Explanation |
| Guicreate |
Create a window. |
| Guictrlcreate... |
Create various controls. |
| Guisetstate |
Display or hide a window. |
| Guigetmsg |
The notification GUI checks for events (only used for message loops ). |
| Guictrlread |
Read control data. |
| Guictrlsetdata |
Set/change control data. |
| Guictrlset... |
Set various properties (color, style, and so on) for the control ). |
Do not forget to include files before writing any GUI scripts.Guiconstants. au3To the beginning of the script (This file contains all the variables and constants used when writing GUI programs ).
Let's create a window, name it "hello", and set its length and width to 200 and 100 pixels respectively. When a window is created, it is hidden. Therefore, we need to show it first.
# Include <guiconstants. au3>
Guicreate ("Hello, 200,100)
Guisetstate (@ sw_show)
Sleep (2000)
If you run the script above, a window appears and disappears two seconds later. It doesn't seem very interesting... let's try to add some text and a confirmation button to the window! We add the text to the Positions 30, 10, and place the buttons in the positions 70, 50. The button width is set to 60 pixels.
# Include <guiconstants. au3>
Guicreate ("Hello, 200,100)
Guictrlcreatelabel ("recently? ", 30, 10)
Guictrlcreatebutton ("OK", 70, 50, 60)
Guisetstate (@ sw_show)
Sleep (2000)
Okay. Now it seems pretty good. But how can we make this GUI respond to the events when we click a button? In this case, we must first determine how to handle the event:Messageloop) OrPassOneventFunction.
Gui Event Mode
As mentioned above, we have two basic GUI modes:Messageloop)Mode andOneventMode. These two modes are different implementation methods for responding to Gui events. Which mode is used depends on yourPersonal preferencesOr the GUI type you want to create. Both modes can be used to create any GUI You Want, but sometimes it is easier to use one of them than the other.
Message loop is the default mode. To switch to onevent mode, use the OPT ("guioneventmode", 1) Statement.
Message Cycle Mode (default)
In message loop mode, the script executes a short cycle most of the time. This cycle notifies the GUI to use the guigetmsg function. When an event occurs, the guigetmsg function returns the message as a return value (for example, if a button is pressed, the GUI is disabled, and so on ).
In this mode, events can only be received when the guigetmsg function is frequently used. Therefore, you must ensure that the function is called several times each second, otherwise, your GUI will not be able to respond to the event.
This mode is most suitable for GUI-focused scripts, and you are most concerned with waiting for user events.
For more details about the message loop mode, please refer to this page.
Onevent Mode
In onevent mode, the script does not need to frequently require the GUI to check whether any event occurs (and process the event based on the returned information ), instead, the GUI temporarily suspends the script and calls a predefined function to process the event only when an event occurs. For example, if you click button 1, the GUI suspends the main script and calls a predefined user function to process the button 1 event. After the function is processed, it returns to the main script for further execution. This mode is similar to the form method of Visual Basic.
This mode is most suitable for scripts where the GUI is second-important and your script needs to execute other tasks first.
For more details about onevent mode, please refer to this page.