ASPit - Totally ASP JSit - Totally JavaScript
Search PHPit

Use this textbox to search for articles on PHPit. Seperate keywords with a space.

Advertisements

An Introduction to the Winbinder Library, Part 1

(Page 3 out of 3)

The Event Handler

The best way to explain the event handler is with an example. Let's say you want to create a clickable button which must display a message when it's clicked. This is where the event handler is used. See the below example:

// Include Winbinder library
include ("D:\WinBinder\phpcode\include/winbinder.php");

// Control Identifiers
define("ID_BUTTON", 101);

// Create main window and set event handler
$mainwin = wb_create_window(NULL, PopupWindow, "Click a button", 200, 200);
wb_set_handler($mainwin, "process_main");

// Create label control inside the window
wb_create_control($mainwin, PushButton, "Click Me"20, 50, 155, 20, ID_BUTTON);

// Enter message loop
wb_main_loop();   

// The event handler, gets called when anything happens
function process_main($window, $id) {
    switch($id) {
                case ID_BUTTON:
                        // Button was clicked
                        wb_message_box($window, "You clicked the button!", "Clicked");
                        break;

                case IDCLOSE:
            wb_destroy_window($window);
            break;
    }
}

?>

When the above example is executed, you will get the following:

Click Button Screenshot 1

And when you click the button, a message box will appear:

Click Button Screenshot 2

In this example we used the event handler to pop up a message box when the button is clicked. To set the event handler we used the wb_set_handler() function.

In the event handler function itself, a switch() statement is used to determine which control has been clicked. To differentiate between different controls, each control must have a unique ID. In the example I defined a constant called 'ID_BUTTON' with a value of 102, and passed this constant as the ID of the button when creating it (see the wb_create_control() function in the example). It's recommended you use constants like I did, instead of manually writing the ID each time.

The Wrap-Up

In this first part I've explained what Winbinder is, and given you a brief look at how it works. It might sound all a bit simple, and we haven't covered anything really advanced yet, but don't be fooled by this, because Winbinder can do so much more.

I highly suggest you look at the Winbinder examples online or look at the examples that come with the Winbinder download.

In the next part we'll dive a bit deeper into Winbinder, and explore some more features. Things you can look forward to are database integration (SQLite and MySQL), low-level DLL functionality, tab controls, listviews, multiple windowed applications, and more.

If you have any questions or comments on this article, feel free to leave them below. Also don't forget to join us at PHPit Forums to talk more about Winbinder, and other interesting PHP topics.

« Previous: Hello World



3 Responses to “An Introduction to the Winbinder Library, Part 1”

  1. giverhard.com » Windbinder - Creating windows apps with PHP Says:

    […] Tutorial Source: PhpIt.net - Download […]

  2. Michal Kuklis Says:

    looks really need. I would like to see some examples involving sql; plus is there any way to integrate it with web applications?? It would be great for example to have a website with pictures and then create something in Winbinder to upload pictures on it. Something like Flickr does.

  3. Harry D Says:

    This is really impressive.
    I think it could be also good for user authentification. Though it is necessary to encrypt traffic at client side and decrypt on server side, as well as updating the client software with different algorithms to avoid a security leak through cracking the code by reverse engineering.

Leave a Reply

About the author
Dennis Pallett is the main contributor to PHPit. He owns several websites, including ASPit and Chill2Music. He is currently still studying.
Article Index
  1. Introduction
  2. Hello World
  3. The Event Handler
Bookmark Article
Download Article
PDF
Download this article as a PDF file