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

 A custom-drawn window that pops up from the taskbar and can be dragged around

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

//------------------------------------------------------------ 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", "Pop me up");		// The window title will be seen in the taskbar and on Alt+tab

define("WIDTH", 				200);
define("HEIGHT",				400);
define("CAPTION_HEIGHT",		30);
define("ID_MINIMIZE",			101);

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

// Only one instance of application allowed

if(wb_get_instance(APPNAME, TRUE))
	die;

// Create main window

$dim = explode(" ", wb_get_system_info("workarea"));

$mainwin = wb_create_window(NULL, NakedWindow, APPNAME,
	$dim[2] - WIDTH, $dim[3] - HEIGHT, WIDTH, HEIGHT, WBC_INVISIBLE | WBC_TOP | WBC_TASKBAR);
wb_set_area($mainwin, WBC_TITLE, 0, 0, WIDTH, CAPTION_HEIGHT);

// Draw and create window background

draw_on_window($mainwin, WIDTH, HEIGHT);

// Create the Minimize and Close buttons

$btn = wb_create_control($mainwin, PushButton, "",	WIDTH - 44, 5, 20, 20, ID_MINIMIZE, WBC_IMAGE);
wb_set_image($btn, wb_load_image(PATH_RES . 'dn_arrow.bmp'), GREEN);

$btn = wb_create_control($mainwin, PushButton, "",	WIDTH - 22, 5, 20, 20, IDCLOSE, WBC_IMAGE);
wb_set_image($btn, wb_load_image(PATH_RES . 'cancel.bmp'), LIGHTGRAY);

// Create other controls with ImageButtons

$states = wb_load_image(PATH_RES . 'states.bmp');
$ypos = CAPTION_HEIGHT + 10;

$btn = wb_create_control($mainwin, ImageButton, "Button 1",  6, $ypos, 32, 32, 0, WBC_IMAGE);
wb_set_image($btn, $states, GREEN);
$btn = wb_create_control($mainwin, ImageButton, "Button 2",	38, $ypos, 32, 32, 0, WBC_IMAGE);
wb_set_image($btn, $states);
$btn = wb_create_control($mainwin, ImageButton, "Button 3",	70, $ypos, 32, 32, 0, WBC_IMAGE);
wb_set_image($btn, $states);
$btn = wb_create_control($mainwin, ImageButton, "Button 4",100, $ypos, 32, 32, 0, WBC_IMAGE);
wb_set_image($btn, $states);
$btn = wb_create_control($mainwin, ImageButton, "Button 5",132, $ypos, 32, 32, 0, WBC_IMAGE);
wb_set_image($btn, $states);
$btn = wb_create_control($mainwin, ImageButton, "Button 6",164, $ypos, 32, 32, 0, WBC_IMAGE);
wb_set_image($btn, $states);

wb_destroy_image($btn);

// Last touches

wb_set_handler($mainwin, "process_main");
wb_set_image($mainwin, PATH_RES . 'hyper.ico');		// Icon will be seen in the taskbar and on Alt+tab
wb_set_visible($mainwin, TRUE);
wb_set_size($mainwin, WBC_MINIMIZED);				// Minimize the main window

wb_main_loop();

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

// Process main window commands

function process_main($window, $id)
{
    switch($id) {

        case ID_MINIMIZE:
			wb_set_size($window, WBC_MINIMIZED);
        	break;

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

// Draw main window image

function draw_on_window($window, $width, $height)
{
	// Create a bitmap and draw on it

	$bkg = wb_create_image($width, $height);

	// Draw the caption area

	wb_draw_rect($bkg, 0, 0, $width, CAPTION_HEIGHT, 0x8D5A2D);
	wb_create_font("Verdana", 14, 0x80FFFF);
	wb_draw_text($bkg, APPNAME, 10, 0, $width, CAPTION_HEIGHT, null);

	// draw a big rectangle

	wb_draw_rect($bkg, 0, CAPTION_HEIGHT, $width, HEIGHT - CAPTION_HEIGHT, 0x803030);

	// Create a Frame control that occupies the whole window

	$frame = wb_create_control($window, Frame, "", 0, 0, $width, $height, 0, WBC_IMAGE);

	// Assign the bitmap to it, then destroy the original bitmap

	wb_set_image($frame, $bkg);
	wb_destroy_image($bkg);
}

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

?>