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

Edited: 2017-02-10 21:41
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.
Parameters
| Control ID | The ID of the control to be changed, this is often saved in a variable. |
| State | Refer to the state-table below this table. |
| $GUI_UNCHECKED | Will uncheck a Radio, Checkbox or ListViewItem. |
| $GUI_CHECKED | Will check a Radio, Checkbox or ListViewItem. |
| $GUI_INDETERMINATE | A Checkbox with the tristate attribute will be greyed. |
| $GUI_AVISTART | An AVI control will start playing. |
| $GUI_AVISTOP | An AVI control will stop playing. |
| $GUI_AVICLOSE | An AVI control will stop playing, and release the source file. |
| $GUI_DROPACCEPTED | Control will accept drag and drop of files, or other GUI controls. |
| $GUI_NODROPACCEPTED | Control will not accept drag and drop. |
| $GUI_SHOW | Will make a hidden control become visible. |
| $GUI_HIDE | Will hide a control entirely. |
| $GUI_ENABLE | Enables a control for use. |
| $GUI_DISABLE | Disables a control from use by graying it out. |
| $GUI_NOFOCUS | Control will lose focus. |
| $GUI_FOCUS | Control will be given focus. |
| $GUI_DEFBUTTON | Control will be set as default button on the window. |
| $GUI_EXPAND | TreeViewItem will expand its child items. |
| $GUI_ONTOP | Control 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.
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)
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()
GUICtrlSetState($Button2, $GUI_DISABLE)
; Run the GUI until the window is closed
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
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')
EndSelect
WEnd
EndFunc
Links
- GUICtrlSetState - autoitscript.com

Tell us what you think: