PHP-HUM Tutorial

PHP-HUM takes advantage of the CLI SAPI (Command Line Interface / Server Application Programming Interface) from PHP. Custom DLLS extends PHP so it is possible to use the language to build a Windows development platform. PHP-HUM includes code to manage windows, controls, messages, timers, the registry, GDI (Windows' Graphics Device Interface) and more. A set of low-level functions allows the programmer to access any Windows function, declare structures and access memory directly.


A callback mechanism allows the application script to easily process Windows messages generated by controls and timers, which are translated to simple callback events that can be handled easily by the PHP code using a single switch statement. Optional filters provide additional features like mouse and keyboard message processing.

The main loop

The Windows main loop is done by as a single function call, wb_main_loop(), that must be called if the application has a window. This function uses the standard Windows approach, that is, a loop that uses the API function GetMessage() to retrieve a message from the queue and DispatchMessage() to send it to the window procedure.There are a few special cases where a Windows programs will not need a message loop, namely when the only tasks to be performed are the creation of message boxes or system dialog boxes. For example:

// This program does not need a call to wb_main_loop()
// Include embed function
function _f($file, $force = false) {
	return $force || defined('EMBEDED')?'res:///PHP/' . md5($file):$file;
include(_f('SDK.php')); //Include SDK
if(wb_message_box(null, "This program has no Windows loop.\nCan you believe it?", null, WBC_YESNO))

Callback functions and window handlers

PHP-HUM 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 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]]])

The name fn_handler is a placeholder for the actual function 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 and param2 are custom values that depend on the class of the control that generated the message.

The callback function must be assigned to a window by a call to wb_set_handler(). In the callback function, param1 can receive the value IDDEFAULT to refer to the parent window itself instead of a control.

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: