Saturday, June 20, 2009

The native windows dinding for php

WinBinder is a new open source extension for PHP, the script programming language. It allows PHP programmers to easily build native Windows applications. Click here for more information.

Some key benefits

  • A small set of WinBinder functions encapsulates many complex aspects of the Windows API and makes programming for Windows an easy task.
  • No compiling and linking steps necessary: just code and run.
  • Interfaces directly to the Window API. This means fast execution, no extra libraries and no installation required.
  • Access to the vast range of existing PHP functions and extensions, including databases, graphics, web functions, XML, PDF, and much more.

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;
}
}

?>

No comments: