<?php

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

 WINBINDER - A native Windows binding for PHP

 Copyright  2004-2005 Hypervisual - see LICENSE.TXT for details
 Author: Rubem Pechansky (http://www.hypervisual.com/winbinder/contact.php)

 Technique to avoid several global variables using a simple class

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

//------------------------------------------------------------ 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);

//----------------------------------------------------------- CLASS DECLARATIONS

// Declare all properties that need intialization inside a class...

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

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

// ... then instantiate the class with one global variable

$wb = new Wb;

// Create main window

create_main_window();

// Enter application loop

wb_main_loop();

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

function create_main_window()
{
    global 
$wb;             // Here is the global variable declaration

    // Properties can be defined on the fly

    
$wb->mainwin wb_create_window(NULLAppWindowAPPNAME " - PHP " PHP_VERSION320240);
    
wb_set_handler($wb->mainwin"process_main");
    
wb_set_image($wb->mainwinPATH_RES "hyper.ico");

    
// Create menu

    
wb_create_control($wb->mainwinMenu, array(
        
"&File",
            array(
ID_OPEN,  "&Open...\tCtrl+O"NULLPATH_RES "menu_open.bmp""Ctrl+O"),
            
null,           // Separator
            
array(IDCLOSE,  "E&xit\tAlt+F4",    NULLPATH_RES "menu_exit.bmp"),
        
"&Help",
            array(
ID_ABOUT"&About...",        NULLPATH_RES "menu_help.bmp")
    ));

    
// Create toolbar

    
wb_create_control($wb->mainwinToolBar, array(
        
null,                                   // Toolbar separator
        
array(ID_OPEN,  NULL,   "Open a file",              1),
        
null,                                   // Toolbar separator
        
array(ID_ABOUTNULL,   "About this application",   13),
        array(
IDCLOSE,  NULL,   "Exit this application",    14),
    ), 
00161500PATH_RES "toolbar.bmp");

    
// Create status bar

    
$wb->statusbar wb_create_control($wb->mainwinStatusBarAPPNAME);

    
// Create label control inside the window

    
wb_create_control($wb->mainwinLabel"This is a demo 'Hello world'\n" .
      
"application made with WinBinder.\n" .
      
"It has a toolbar, a status bar and a menu.",
      
1070290800WBC_CENTER);
}

/* Process main window commands */

function process_main($window$id)
{
    global 
$wb;             // Here is the global variable declaration

    
switch($id) {

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

        case 
ID_OPEN:
            
$wb->filename wb_sys_dlg_open($window"Get It"$wb->file_filter);
            if(
$wb->filename)
                
wb_set_text($wb->statusbar$wb->filename);
            break;

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

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

?>