Creating WinBinder applications

There are five steps needed to create a WinBinder application:

  1. Create the main window.
  2. Create controls for the main window.
  3. Create a handler function to process the controls.
  4. Assign the handler function to the main window.
  5. Enter the application loop.

Example

The simple example below creates a very basic WinBinder application with two button controls. The comments show the required steps.

<?
include "../include/winbinder.php";                 // Location of WinBinder library

// STEP 1: Create main window

$mainwin = wb_create_window(NULL, AppWindow, "Five steps", 320, 240);

// STEP 2: Create controls for the main window       Geometry data        Id

wb_create_control($mainwin, PushButton, "Button 1",   50, 70, 80, 22,     101);
wb_create_control($mainwin, PushButton, "Button 2",  180, 70, 80, 22,     102);

// STEP 3: Create a handler function to process the controls (see below).

// STEP 4: Assign the handler function to the main window.

wb_set_handler($mainwin, "process_main");

// STEP 5: Enter application loop

wb_main_loop();

// The handler function from step 3

function process_main($window, $id)
{
    switch($id) {

        case 101:
        case 102:
            wb_message_box($window, "Button #$id was pressed.");
            break;

        case IDCLOSE:                         // The constant IDCLOSE is predefined
            wb_destroy_window($window);       // Destroy the window
            break;
     }
}

?>


See also

The main loop
Callback functions and window handlers