By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

AutoIt GUICtrlSetState Function

The GUICtrlSetState Function is used to control the state of GUI elements.

Edited: 2014-12-31 03:24

The AutoIt GUICtrlSetState Function is used to change the state of GUI elements. An example would be when pressing a button that triggers a function, disabling the button while the function is running can avoid confusion.

Returns 1 on success, and 0 on failure.


Control IDThe ID of the control to be changed, this is often saved in a variable.
StateRefer to the state-table below this table.
$GUI_UNCHECKEDWill uncheck a Radio, Checkbox or ListViewItem.
$GUI_CHECKEDWill check a Radio, Checkbox or ListViewItem.
$GUI_INDETERMINATEA Checkbox with the tristate attribute will be greyed.
$GUI_AVISTARTAn AVI control will start playing.
$GUI_AVISTOPAn AVI control will stop playing.
$GUI_AVICLOSEAn AVI control will stop playing, and release the source file.
$GUI_DROPACCEPTEDControl will accept drag and drop of files, or other GUI controls.
$GUI_NODROPACCEPTEDControl will not accept drag and drop.
$GUI_SHOWWill make a hidden control become visible.
$GUI_HIDEWill hide a control entirely.
$GUI_ENABLEEnables a control for use.
$GUI_DISABLEDisables a control from use by graying it out.
$GUI_NOFOCUSControl will lose focus.
$GUI_FOCUSControl will be given focus.
$GUI_DEFBUTTONControl will be set as default button on the window.
$GUI_EXPANDTreeViewItem will expand its child items.
$GUI_ONTOPControl will be given the ontop attribute, making it show on top of other elements (zOrdering).

States can be combined, I.e. $GUI_DISABLE + $GUI_HIDE will set the control in an disabled and hidden state.

AutoIt GUICtrlSetState Example

The below example scripts creates a GUI with Two Buttons, then lets you control the availability of the second button by pressing the first.

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)


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)

  GUICtrlSetState($Button2, $GUI_DISABLE)

  ; Run the GUI until the window is closed
  While 1
    $msg = GUIGetMsg()
     Case $msg = $GUI_EVENT_CLOSE
     Case $msg = $Button1
       GUICtrlSetState($Button1, $GUI_DISABLE)
       GUICtrlSetState($Button2, $GUI_ENABLE)
       MsgBox(0, 'Button 1', 'Button 1 was pressed')
     Case $msg = $Button2
       GUICtrlSetState($Button1, $GUI_ENABLE)
       GUICtrlSetState($Button2, $GUI_DISABLE)
       MsgBox(0, 'Button 2', 'Button 2 was pressed')