<?php

/*******************************************************************************

 WINBINDER - The native Windows binding for PHP for PHP

 Copyright © Hypervisual - see LICENSE.TXT for details
 Author: Rubem Pechansky (http://winbinder.org/contact.php)

 Code sample: "Hello world" application

*******************************************************************************/

//------------------------------------------------------------ SYSTEM PARAMETERS

define("PATH_SCRIPT",	dirname(__FILE__) . "/");
define("PATH_DATA",		PATH_SCRIPT);
define("PATH_INC",		PATH_SCRIPT . "../include/");
define("PATH_RES",		PATH_SCRIPT . "../resources/");

//----------------------------------------------------------------- DEPENDENCIES

include PATH_INC . "winbinder.php";

//-------------------------------------------------------------------- CONSTANTS

define("APPNAME",           "Hello world!");    // Application name

// Control identifiers

define("ID_ABOUT",          101);
define("ID_OPEN",           102);

//-------------------------------------------------------------- EXECUTABLE CODE

// Create main window, then assign a procedure and an icon to it

$mainwin = wb_create_window(NULL, AppWindow, APPNAME . " - PHP " . PHP_VERSION, 320, 240);
wb_set_handler($mainwin, "process_main");
wb_set_image($mainwin, PATH_RES . "hyper.ico");

// Create menu

wb_create_control($mainwin, Menu, array(
    "&File",
        array(ID_OPEN,  "&Open...\tCtrl+O", NULL, PATH_RES . "menu_open.bmp", "Ctrl+O"),
        null,           // Separator
        array(IDCLOSE,  "E&xit\tAlt+F4",    NULL, PATH_RES . "menu_exit.bmp"),
    "&Help",
        array(ID_ABOUT, "&About...",        NULL, PATH_RES . "menu_help.bmp")
));

// Create toolbar

wb_create_control($mainwin, ToolBar, array(
    null,                                   // Toolbar separator
    array(ID_OPEN,  NULL,   "Open a file",              1),
    null,                                   // Toolbar separator
    array(ID_ABOUT, NULL,   "About this application",   13),
    array(IDCLOSE,  NULL,   "Exit this application",    14),
), 0, 0, 16, 15, 0, 0, PATH_RES . "toolbar.bmp");

// Create status bar

$statusbar = wb_create_control($mainwin, StatusBar, APPNAME);

// Create label control inside the window

wb_create_control($mainwin, Label, "This is a demo 'Hello world'\n" .
  "application made with WinBinder.\n" .
  "It has a toolbar, a status bar and a menu.",
  10, 70, 290, 80, 0, WBC_CENTER);

// Enter application loop

wb_main_loop();

//-------------------------------------------------------------------- FUNCTIONS

/* Process main window commands */

function process_main($window, $id)
{
    global $statusbar;

    static $file_filter = array(
        array("PHP source code",    "*.php?"),
        array("Web page",           "*.htm?"),
        array("Text document",      "*.txt"),
        array("All files",          "*.*")
    );

    switch($id) {

        case ID_ABOUT:
            wb_message_box($window, "WinBinder version " . WBC_VERSION .
              "\nPHP version " . PHP_VERSION .  "\n" .
              wb_get_system_info("osversion"), "About " . APPNAME, WBC_INFO);
            break;

        case ID_OPEN:
            $filename = wb_sys_dlg_open($window, "Get It", $file_filter);
            if($filename)
                wb_set_text($statusbar, $filename);
            break;

        case IDCLOSE:       // IDCLOSE is predefined
            wb_destroy_window($window);
            break;
    }
}

//------------------------------------------------------------------ END OF FILE

?>