# Function Reference

GUICtrlSetState

Changes the state of a control.

GUICtrlSetState ( controlID, state )

Parameters

controlID | The control identifier (controlID) as returned by a GUICtrlCreate... function.
state | See the State table below.

Return Value

Success: | Returns 1.
Failure: | Returns 0.

Remarks

State table

State | Comments
No Change | 0
$GUI_UNCHECKED | Radio or Checkbox will be unchecked
$GUI_CHECKED | Radio or Checkbox will be checked
$GUI_INDETERMINATE | Checkbox having the tristate attribute will be greyed
$GUI_AVISTART | Avi control will start playing
$GUI_AVISTOP | Avi control will stop playing
$GUI_AVICLOSE | Avi control will stop playing and release resource
$GUI_DROPACCEPTED | Control will accept drop action : from file or from a drag of another control. See remarks
$GUI_SHOW | Control will be visible. On Tabitem control will select the first tab to be displayed
$GUI_HIDE | Control will not be visible
$GUI_ENABLE | Control will be enabled
$GUI_DISABLE | Control will be greyed out
$GUI_FOCUS | Control will be given input/selected focus
$GUI_DEFBUTTON | Control will be set as the default button on the window
$GUI_EXPAND | TreeViewItem will expand it's child items.
$GUI_ONTOP | Control will be have the ontop attribute for the window (zOrdering).

State values can be summed up as for example $GUI_DISABLE + $GUI_HIDE sets the control in an disabled and hidden state.
If an AVI control has to be hidden with $GUI_HIDE it should be closed with $GUI_AVICLOSE.
State of a "contextmenu" or "menu" control cannot be changed.
! Important information for $GUI_EXPAND: this state is only used for TreeViewItems. If you want to use this 'action' then at least 1 Sub-TreeViewItem has to exist/created under this item !
If you want to select another item in a TreeView then you can use $GUI_FOCUS - the parent TreeView gets the window focus and the specified item is marked as selected.
If you want to set a treeview item as a default item which means painting it bold you can use $GUI_DEFBUTTON - to turn it off just use another value but $GUI_DEFBUTTON, for instance 0.
If $GUI_DROPACCEPTED is set to a visible control a drag&drop can be taken in account. The edit/input control will be set with the filename.
For other controls on reception of $GUI_EVENT_DROPPED, @GUI_DRAGID will return the controlID from where the drag start (-1 if from a file, @GUI_DRAGFILE contain the filename being dropped) and @GUI_DROPID returns the controlID of the dropped control.
Only dragging a ListviewItem will start the drag & drop process. The @GUI_DRAGID will be the ListView controlID.

Related

ColorMode (Option), GUICtrlCreate..., GUICtrlSetData

Example

#include <GUIConstants.au3>
GUICreate("My GUI state") ; will create a dialog box that when displayed is centered
GUICtrlCreateLabel ("my disable label", 10,20)
GUICtrlSetState(-1,$GUI_DISABLE) ; the label is in disable state
GUICtrlCreateButton ("my button", 50,50)
GUICtrlSetState(-1,$GUI_FOCUS) ; the focus is on this button
GUISetState ()
; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend