Registers a function or method to be called when a control notification is received via the WM_COMMAND message.
GuiControl.OnCommand(NotifyCode, Callback , AddRemove := 1)
The GuiControl object of the control to monitor.
The control-defined notification code to monitor.
Type: String or Object
The function, method or object to call when the event is raised.
If this parameter is a string, its meaning depends on whether the GUI has an event sink (that is, whether Gui.New's EventObj parameter was specified). If the GUI has an event sink, the string must be the name of a method belonging to the event sink; otherwise, it must be the name of a function.
To register a function regardless of whether the GUI has an event sink, pass a function reference.
One of the following values:
1 (the default): Call the callback after any previously registered callbacks.
-1: Call the callback before any previously registered callbacks.
0: Do not call the callback.
Certain types of controls send a WM_COMMAND message whenever an interesting event occurs. These are usually standard Windows controls which have been around a long time, as newer controls use the WM_NOTIFY message (see OnNotify). Commonly used notification codes are translated to events, which the script can monitor with OnEvent.
The message's parameters contain the control ID, HWND and notification code, which AutoHotkey uses to dispatch the notification to the appropriate callback. There are no additional parameters.
To determine which notifications are available (if any), refer to the control's documentation. Control Library (MSDN) contains links to each of the the Windows common controls (however, only a few of these use WM_COMMAND). The notification codes (numbers) can be found in the Windows SDK, or by searching the Internet.
The notes for OnEvent regarding
this and bound functions also apply to OnCommand.
The callback receives one parameter:
If multiple callbacks have been registered for an event, a callback may return a non-empty value to prevent any remaining callbacks from being called.
The return value is ignored by the control.
These notes for OnEvent also apply to OnCommand: Threads, Destroying the GUI.
OnNotify can be used for notifications which are sent as a WM_NOTIFY message.