## Callback functions and window handlers

WinBinder implements a callback mechanism so the application script can easily process the events generated by controls or timers. While the main loop is active, the various controls and objects keep sending messages to the main application window whenever an event occurs. For example, if the user clicks a button or selects an item from a list view, a message is generated and transmitted to the function assigned as the current window handler.

# The callback function

The callback function (or method) can have any valid PHP function name and has the following prototype:

void fn_handler (int window, int id [, int ctrl [, int param1 [, int param2 [, int lparam3]]]])

The name fn_handler is a placeholder for the actual function or method name. The parameter window is the window handle, id is the identifier of the object that generated the message, ctrl is the control (if it is the case) that generated the message, and param1, param2 and param3 are custom values that depend on the class of the control that generated the message.

The callback function or method must be assigned to a window by a call to wb_set_handler().

NOTE: In the callback function, param1 can receive the value `IDDEFAULT` to refer to the parent window itself instead of a control.

# Events

Look at the table in the window messages and events page to see the events generated from all control classes.

# Notification message flags

To enable additional messages in a particular window, you must include `WBC_NOTIFY` in the wb_create_window() function style parameter when creating the window and use param to indicate which additional notification messages you want to process. The flags are passed to the callback function via param1. The following notification flags are available:

Notification flag | Sent when
--- | ---
`WBC_DBLCLICK` | The control or the parent window was double-clicked.
`WBC_MOUSEMOVE` | The mouse cursor was moved over the main window.¹
`WBC_MOUSEDOWN` | A mouse button was pressed on the main window.¹
`WBC_MOUSEUP` | A mouse button was released on the main window.¹
`WBC_KEYDOWN` | A key was pressed when a given control has the focus.¹
`WBC_KEYUP` | A key was released when a given control has the focus.¹
`WBC_GETFOCUS` | A control has received the keyboard focus.
`WBC_REDRAW` | A request for screen redraw was posted on the message queue.
`WBC_RESIZE` | The parent window was resized.
`WBC_HEADERSEL` | A ListView column header was clicked or a TabControl tab is changed.

¹ Mouse and keyboard notification messages can be further filtered using the following additional notification message flags:

`WBC_ALT
WBC_CONTROL
WBC_SHIFT
WBC_LBUTTON
WBC_MBUTTON
WBC_RBUTTON`

# See also

wb_main_loop
wb_set_handler
Window messages and events
The main loop