<?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)

 Minimize / restore windows, change taskbar icon

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

//------------------------------------------------------------ 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",	"Test taskbar icon");

// Control identifiers

define("IDC_SECWIN",		101);
define("IDC_STATE",			102);
define("ID_TIMER",			103);

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

create_main_window();
wb_main_loop();

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

function create_main_window()
{
	global $mainwin, $statusbar, $mainmenu, $mainwin;

	// Create main window (invisible)

	$mainwin = wb_create_window(NULL, AppWindow, APPNAME,
		WBC_CENTER, WBC_CENTER, 320, 140, WBC_INVISIBLE, 0);
	wb_set_handler($mainwin, "process_main");

	// Insert controls

	wb_create_control($mainwin, PushButton, "&Create secondary window", 80, 20, 150, 25, IDC_SECWIN);
	wb_create_control($mainwin, PushButton, "Change &state", 80, 60, 150, 25, IDC_STATE, WBC_DISABLED);
	wb_create_timer($mainwin, ID_TIMER, 1000);

	// Show main window

	wb_set_visible($mainwin, true);
}

function process_main($window, $id)
{
	global $secwin;
	static $state = false;

	switch($id) {

		case IDC_SECWIN:
			if(!$secwin) {
				$secwin = wb_create_window($window, AppWindow, "Minimize me!", 100, 100, 200, 100, WBC_TASKBAR);
				wb_set_image($secwin, PATH_RES . "hyper.ico");
				wb_set_handler($secwin, "process_dlg");
				wb_set_enabled(wb_get_control($window, IDC_STATE), TRUE);
			}
			break;

		case IDC_STATE:

			if(!$secwin)
				break;

			$size = wb_get_size($secwin);
			if($size == WBC_MINIMIZED)
				wb_set_size($secwin, WBC_NORMAL);
			else
				wb_set_size($secwin, WBC_MINIMIZED);
			break;

		case ID_TIMER:

			if(!$secwin)
				break;

			wb_set_image($secwin, PATH_RES . ($state ? "ttf.ico" : "hyper.ico"));
			$state = !$state;
			wb_play_sound(WBC_BEEP);
			break;

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

function process_dlg($window, $id)
{
	global $mainwin, $secwin;

	switch($id) {

		case IDCLOSE:
			wb_destroy_window($window);
			$secwin = NULL;
			wb_set_enabled(wb_get_control($mainwin, IDC_STATE), FALSE);
			break;
	}
}

//-------------------------------------------------------------------------- END

?>