<?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: A simple digital clock with scrolling text

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

//------------------------------------------------------------ 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("ID_APP_TIMER",	201);
define("SHORT_FMT",		"h:i:s A");
define("LONG_FMT",		"l, F dS, Y --- ");

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

// Create main window, then assign a procedure to it

$mainwin = wb_create_window(NULL, PopupWindow, "WB clock", 120, 90);
wb_set_handler($mainwin, "process_main");

// Create label control inside the window

$label = wb_create_control($mainwin, Label, date("h:i:s A"), 0, 12, 112, 20, 0, WBC_CENTER);
wb_set_font($label, wb_create_font("Tahoma", 11, null, FTA_BOLD));

// Create status bar

$statusbar = wb_create_control($mainwin, StatusBar, date(SHORT_FMT));
wb_set_font($statusbar, wb_create_font("Courier New", 8));

// Create the timer

wb_create_timer($mainwin, ID_APP_TIMER, 120);

// Enter application loop

wb_main_loop();

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

/* Process main window commands */

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

	switch($id) {

		case ID_APP_TIMER:

			// Show the current time in hours, minutes and seconds

			wb_set_text($label, date(SHORT_FMT));

			// Truncate text

			$text = date(LONG_FMT);
			$len = strlen($text);
			wb_set_text($statusbar, substr($text . $text, $pos, $len));
			$pos = $pos < $len ? $pos + 1 : 0;
			break;

		case IDCLOSE:

			wb_destroy_window($window);
			break;
    }
}

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

?>