AutoIt GUI related knowledge _autoit

Source: Internet
Author: User
Tags sleep

The concept of GUI

A GUI can consist of one or more Windows with one or more controls. The GUI relies on "event-driven" to interact with the user, such as clicking on a button that triggers an event. When the program is idle, it waits for the occurrence of the event, and when it catches the event, it performs the relevant action according to the event. You can imagine yourself waiting at the door for the postman (sitting there until a letter is sent in), wait for the postman to send the letter, you have to read the letter and decide what to do next, this is the same as the GUI principle: You wait for the postman, and the GUI is waiting for the event,

Of course, you can also choose other tasks to do when the GUI (the interface to the program) is running, such as using a GUI function to create a dynamic progress bar that is automatically updated, while performing other complex tasks.

GUI's controls

All users should have a good understanding of the controls, and the parts of the window that can be clicked or otherwise interacting are one of the controls. There are several types of controls that AutoIt can create (you must have seen them in other Windows programs):

  • Label
  • Plain text controls
  • Button
  • Button
  • Input
  • Single-line edit box for entering text
  • Edit
  • Multi-line edit box for input text
  • Checkbox
  • Box button, which can be selected or unchecked
  • Radio
  • Round button (usually several groups, only activate/select one at a time)
  • Combo
  • Combo box with Drop-down list
  • List
  • list box
  • Date
  • Date selection
  • Pic
  • Image
  • Icon
  • Icon
  • Progress
  • Progress bar
  • Tab
  • Labels, each of which can contain a set of controls
  • UpDown
  • Can be attached to an input control
  • Avi
  • Show clips in AVI format
  • Menu
  • The menu at the top of the window
  • ContextMenu
  • The menu that appears when you right-click on a window
  • Treeview
  • Windows-like Resource Manager (tree view)
  • Slider
  • A volume control similar to Windows (slider bar)
  • Listview
  • Controls that display information by column (List view)
  • ListViewItem
  • ListView control's Project
  • Dummy
  • Virtual User Control

    The following is a single Window GUI example that contains a number of controls that are supported by AutoIt. From which we can see that AutoIt can indeed create very rich gui!

    Use guictrlcreate ... function to create a control. The function returns the control IDwhen it is created. There are several things to note about control IDs:

  • The control ID is a positive number (meaning that it is greater than 0)
  • Each control ID is unique (even if more than one window exists).
  • The control ID can be obtained by AutoIt Window Info.

    GUI Basic Functions

    Here are the functions you can use to create a GUI. But these are relatively rudimentary applications, and if you are ready to create a more advanced GUI, there are other advanced functions as well.

    Function Explain
    Guicreate Create a window.
    Guictrlcreate ... Create various controls.
    Guisetstate Shows or hides the window.
    Guigetmsg Notifies the GUI to detect whether an event has occurred (only for message loops).
    Guictrlread Reads the control data.
    Guictrlsetdata Sets/changes the data for the control.
    Guictrlset ... Make various property settings (colors, styles, and so on) for the control.

    Before you start writing any GUI scripts, don't forget to include the file Guiconstants.au3 to the beginning of the script (which contains all the variables and constants you need to use to write the GUI program).

    Let's first create a window, name it "Hello", and set its length to 200 and 100 pixels respectively. When the window is created it is hidden, so we have to give it to show.

    #include <GUIConstants.au3>

    Guicreate ("Hello", 200, 100)
    Guisetstate (@SW_SHOW)
    Sleep (2000)

    If you run the above script you will see a window appear and disappear after two seconds. It's not very interesting. So let's try adding some text and a OK button to the window! We add the text to the 30, 10 position and put the button in the position of 70, 50, and the button width is set to 60 pixels.

    #include <GUIConstants.au3>

    Guicreate ("Hello", 200, 100)
    Guictrlcreatelabel ("How have you Been?") ", 30, 10)
    Guictrlcreatebutton ("OK", 70, 50, 60)
    Guisetstate (@SW_SHOW)
    Sleep (2000)

    Well, it looks good now. But how do you make this GUI respond to the events we clicked on the button? At this point we must first decide what to do with the event: either through the message loop (messageloop) or through the OnEvent function.

    GUI Event Pattern

    As mentioned above, we have two basic GUI schemas: message loop (Messageloop) and OnEvent mode. These two modes are different implementations of the GUI event response. Choose which pattern you prefer, or the type of GUI you want to create. Both of these patterns can be used to create any GUI you want, but sometimes it's better to use one of them than the other.

    The message loop is the default mode. To switch to OnEvent mode, use the OPT ("Guioneventmode", 1) statement.

    Message looping mode (default)

    In the message looping mode, the script spends most of its time performing a very short cycle, which informs the GUI that the guigetmsg (Intercept message) function is used. When an event occurs, the GUIGETMSG function returns the message as a return value (for example, when a button is pressed, the GUI is closed, and so on).

    In this mode, it is only possible to receive events when we use the GUIGETMSG function frequently, so you must make sure that the function is called several times in every second, or your GUI will not respond to events.

    This pattern is best for those GUI-focused scripts, and you are most concerned with waiting for user events.

    For a more detailed explanation of the message looping pattern, see this page.

    OnEvent mode

    In onevent mode, the script does not need to frequently require the GUI to check for any events to occur (and depending on the return information processing event), but only if the GUI pauses the script temporarily and invokes a user-predefined function to handle the event when an event occurs. For example, suppose the user clicks the button 1, the GUI pauses the main script and invokes a predefined user function to handle the button 1 event. The function does not return to the main script until it completes the processing operation. This pattern compares a form method similar to Visual Basic.

    This pattern is best suited for scripts where the GUI is in the second most important position, and your script needs to prioritize other tasks.

    For a more detailed explanation of the onevent mode, please check out this page.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.