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.

Callbacks

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:

<?php
// 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))
    wb_sys_dlg_color(NULL);
?>
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.

Function Reference

  • wb_call_function - Calls a DLL function
  • wb_create_control - Creates a control, menu, or accelerator
  • wb_create_font - Creates a font
  • wb_create_image - Creates an image
  • wb_create_items - Creates one or more items in a control or menu
  • wb_create_mask - Creates a masked (transparent) image
  • wb_create_timer - Creates a timer
  • wb_create_window - Creates a window
  • wb_delete_items - Deletes items from a control or menu
  • wb_destroy_font - Destroys a font
  • wb_destroy_image - Destroys an image
  • wb_destroy_timer - Destroys a timer
  • wb_destroy_window - Destroys a window
  • wb_destroy_control - Destroys a control
  • wb_draw_image - Draws an opaque or transparent bitmap
  • wb_draw_line - Draws a straight line
  • wb_draw_point - Draws a point of color
  • wb_draw_rect - Draws a filled or hollow rectangle
  • wb_draw_text - Draws a text string
  • wb_exec - Opens or executes a command
  • wb_find_file - Look for a file in the Windows and System directories
  • wb_get_address - Returns the address of a variable
  • wb_get_class - Retrieves the class of a control, window or menu
  • wb_get_control - Returns the handle to a child control in a dialog box or a menu item
  • wb_get_enabled - Tells whether a control is enabled
  • wb_get_function_address - Retrieves the address of a library function
  • wb_get_id - Returns the identifier of a control
  • wb_get_instance - Detects a running instance of a WinBinder application
  • wb_get_item_count - Returns the number of items in an object
  • wb_get_item_list - Returns an array with child items or controls
  • wb_get_level - Retrieves the level of a control item
  • wb_get_parent - Returns the control or item parent
  • wb_get_pixel - Returns the RGB color value of a pixel
  • wb_get_position - Retrieves the position of a control or window
  • wb_get_registry_key - Returns the value of a registry entry
  • wb_get_selected - Returns the selected state of one or more items
  • wb_get_size - Retrieves the size of a control, window or image
  • wb_get_state - Retrieves the state of a control item
  • wb_get_system_info - Returns various data about the current system
  • wb_get_text - Gets the text from a control, window, menu item, an item, or sub-item
  • wb_get_value - Retrieves the value of a control, item, or sub-item
  • wb_get_visible - Tells whether a control is visible
  • wb_load_image - Loads an image file from disk and returns a handle to it
  • wb_load_library - Loads a DLL into memory
  • wb_main_loop - Enters the Windows main loop
  • wb_message_box - Displays a message box
  • wb_peek - Gets the contents of a memory area
  • wb_play_sound - Play a system sound
  • wb_poke - Sets the contents of a memory area
  • wb_refresh - Refreshes or redraws an object
  • wb_release_library - Releases a DLL from memory
  • wb_save_image - Saves an image to disk
  • wb_send_message - Sends a Windows message to an object
  • wb_set_area - Sets a specific area in a window
  • wb_set_enabled - Enables or disables a control
  • wb_set_focus - Assigns the focus to an object
  • wb_set_font - Sets the font of a control
  • wb_set_handler - Assigns a callback function to a window
  • wb_set_image - Assigns an image to an object
  • wb_set_item_image - Assigns a portion of an image to a control item
  • wb_set_location - Sets the location of an HTML control or sends a special command to it
  • wb_set_position - Moves an object
  • wb_set_registry_key - Sets the value of a registry entry
  • wb_set_selected - Selects one or more items of a control
  • wb_set_size - Sets the size of an object
  • wb_set_state - Sets the state of a treeview node
  • wb_set_style - Sets or resets the style of an object
  • wb_set_text - Sets the text of an object
  • wb_set_value - Sets the value(s) and/or the minimum and maximum range of a control
  • wb_set_visible - Shows or hides an object
  • wb_sort - Sorts the contents of a control
  • wb_sys_dlg_color - Displays the standard Select Color dialog box
  • wb_sys_dlg_open - Displays the standard Open dialog box
  • wb_sys_dlg_path - Displays the standard Select Path dialog box
  • wb_sys_dlg_save - Displays the standard Save As dialog box
  • wb_wait - Verifies mouse and keyboard status, create a delay

We use cookies to personalize and enhance your experience on our site. By using our site, you agree to our use of cookies.
  More information about cookies