AutoIt GUICtrlCreateButton Function

How to use the AutoIt GUICtrlCreateButton function to create buttons in GUIs.

2225 views

Edited: 2017-02-10 21:49

The AutoIt GUICtrlCreateButton Function is used to create buttons in GUI windows.

Parameters

TextButton text
pixelsLeft side of control - computed according to GUICoordMode if -1.
pixelsTop of control - computed according to GUICoordMode if -1.
pixels [optional]The width of the control.
pixels [optional]The height of the control.
Style [optional]Controls the style of the window.
ExStyle [optional]Controls the extended style of the window.

Example

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

MainGUI()

Func MainGUI()
  Local $Button1, $Button2, $msg
  GUICreate("My GUI Window Title")

  Opt("GUICoordMode", 2)
  $Button1 = GUICtrlCreateButton("Button 1", 10, 30, 100)
  $Button2 = GUICtrlCreateButton("Button 2", 0, -1)

  GUISetState()

  ; Run the GUI until the dialog is closed
  While 1
    $msg = GUIGetMsg()
    Select
     Case $msg = $GUI_EVENT_CLOSE
       ExitLoop
     Case $msg = $Button1
       MsgBox(0, 'Button 1', 'Button 1 was pressed')
     Case $msg = $Button2
       MsgBox(0, 'Button 2', 'Button 2 was pressed')
    EndSelect
  WEnd
EndFunc

Tell us what you think:

  1. How to create a list of selectable items with AutoIt.
  2. Tutorial on how to make GUIs using the AutoIt scripting language.
  3. How to disable and enable AutoIt GUI elements using GUICtrlSetState.
  4. How to interrupt running functions and handle system events in AutoIt GUI scripting.
  5. Tutorial on how to add images to AutoIt GUIs while maintaining aspect ratio.

More in: AutoIt GUIs