Skip to content
Nikola edited this page May 26, 2024 · 1 revision

Welcome to the GuiEnhancerKit wiki!

OnMessage

Registers a function or method to be called whenever the Gui receives the specified message.

GuiOrCtrlObj.OnMessage(MsgNumber, Callback [, AddRemove])

Parameters

MsgNumber

Type: Integer

The number of the message to monitor.

Callback

Type: String or Function Object

The function, method or object to call when the message is received.

If the GUI has an event sink (that is, if Gui()'s EventObj parameter was specified), this parameter may be the name of a method belonging to the event sink.

Otherwise, this parameter must be a function object.

AddRemove

Type: Integer

If omitted, it defaults to 1 (call the callback after any previously registered callbacks). Otherwise, specify one of the following numbers:

  • 1 = Call the callback after any previously registered callbacks.
  • -1 = Call the callback before any previously registered callbacks.
  • 0 = Do not call the callback.

Callback Parameters

The callback receives up to four parameters:

Callback(GuiOrCtrlObj, wParam, lParam, MsgNumber)

However, refer to the notes for OnEvent, especially regarding this and the GuiOrCtrlObj parameter.

Callback Return Value

If the callback returns a non-empty value, it is used as the message's reply, any remaining callbacks are not called, and the Gui window's default processing of the message is suppressed.

The callback should return either an Integer or an empty string, or not explicitly return.

Remarks

These notes for OnEvent also apply to OnMessage: Threads, Destroying the GUI.

When the callback is called, A_EventInfo and the last found window are set as per Additional Information Available to the Callback.

Gui-specific message callbacks are called after global message callbacks (registered with the OnMessage function), but before the Gui window's own default processing takes place.

The callback function may be called recursively if the message is received while the callback is already running. The number of threads that can be started is limited only by #MaxThreads.

If GuiOrCtrlObj is a control, window subclassing is used to detect or intercept messages sent directly to the control. These messages are not detected by the global OnMessage function.

Related

Gui and GuiControl methods: OnEvent, OnNotify, OnCommand

Functions: OnMessage, PostMessage, SendMessage, Critical, DllCall

Other: List of Windows Messages, Threads

Clone this wiki locally