use Win32::GUI;

my $LabelFont = new Win32::GUI::Font
(
	-bold	=> 1,
	-italic	=> 0,
	-size	=> 18,
	-name	=> "Arial", 
);
my $BTNFont = new Win32::GUI::Font
(
	-bold	=> 1,
	-height	=> 14,
	-name	=> "Arial", 
);

my $Window = new Win32::GUI::Window
(
	-name	=> "Window",
	-text	=> "Blow Up",
	-top	=> 50,
	-left	=> 50,
	-height	=> 150,
	-width	=> 200,
	-style    => 1024 | WS_BORDER | WS_CAPTION | WS_SYSMENU,
);

my $Label = $Window->AddLabel
(
	-name	=> "Message",
	-text	=> "Press this Button",
	-top	=> 20,
	-left	=> 0,
	-height	=> 25,
	-width	=> 200,
	-font	=> $LabelFont,
	-align	=> "center",
	-visible => 1,
);

my $Button = $Window->AddButton
(
	-name	=> "Button",
	-text	=> "Button",
	-top	=> 60,
	-left	=> 60,
	-height	=> 35,
	-width	=> 60,
	-font	=> $BTNFont,
);

sub Button_Click
{
	&MsgBox("Hello World.");

	$Return =  &MsgBox( { ButtonSize => [75, 35], Buttons => [Okay, Exit, Cancel], TimeOut => 6, Message => "How is this? I Hope you like it because I worked really hard on it.", Rect => [300, 150], Pos => [10,100]});

	&MsgBox( {Message => "You pressed $Return."});

	return 1; 
}


$Window->Show;

$Window->BringWindowToTop;

Win32::GUI::Dialog();

exit;



#-----------------------------------------------------------------------------------

sub MsgBox
{
	my ($MessageProps) = @_;

	my ($DefMBWidth, $DefMBHeight, $DefMBButtonWidth, $DefMBButtonHeight, $DefMBTimeOut) = (300, 150, 50, 25, 10);

	local (@MBButtons) = @{$$MessageProps{Buttons}} ? @{$$MessageProps{Buttons}} : ("Okay", "Cancel");

	my $Message = ( $$MessageProps{Message} or $$MessageProps or "Press $MBButtons[0] to continue.");

	my $TimeOut = ( $$MessageProps{TimeOut} or $DefMBTimeOut);

	my ($MBWidth, $MBHeight) = @{$$MessageProps{Rect}} ? @{$$MessageProps{Rect}} : ($DefMBWidth, $DefMBHeight); 

	my ($MBButtonWidth, $MBButtonHeight) = @{$$MessageProps{ButtonSize}} ? @{$$MessageProps{ButtonSize}} : ($DefMBButtonWidth, $DefMBButtonHeight);

	my ($DTTop, $DTLeft, $DTRight, $DTBottom) = Win32::GUI::GetClientRect(Win32::GUI::GetDesktopWindow());

	my ($MBTop, $MBLeft) =  @{$$MessageProps{Pos}} ? @{$$MessageProps{Pos}} : (($DTBottom - $MBHeight) / 2, ($DTRight - $MBWidth ) / 2);

	my $MBLabelFont = new Win32::GUI::Font
	(
		-bold	=> 1,
		-italic	=> 0,
		-size	=> 18,
		-name	=> "Arial", 
	);
	my $MBButtonFont = new Win32::GUI::Font
	(
		-bold	=> 1,
		-height	=> 14,
		-name	=> "Arial", 
	);

	my $MsgBox = new Win32::GUI::Window
	(
		-name	=> "MsgBox",
		-text	=> "Message Box",
		-top	=> $MBTop,
		-left	=> $MBLeft,
		-height	=> $MBHeight,
		-width	=> $MBWidth,
		-style    => 1024 | WS_BORDER | WS_CAPTION | WS_SYSMENU,
	);

	my $MBTimeOut = $MsgBox->AddTimer("MBTimeOut", $TimeOut * 1000);

	my $MBLabel = $MsgBox->AddLabel
	(
		-name	=> "Message",
		-text	=> $Message,
		-top	=> $MBHeight * .1,
		-left	=> $MBWidth * .2,
		-height	=> $MBHeight * .4,
		-width	=> $MBWidth * .6,
		-font	=> $MBLabelFont,
		-align	=> "center",
		-visible => 1,
	);

	my $Ctr = 1;
	my $MBButtonMessage;
	my %MBButton;
	foreach $MBButtonMessage ( @MBButtons )
	{
		my $MBButtonBuffer = ($MBWidth * .8 - ( $MBButtonWidth * ($#MBButtons + 1) ) ) / ($#MBButtons + 2);
 
		$MBButton{$MBButtonMessage} = $MsgBox->AddButton
		(
			-name	=> "MBButton$Ctr",
			-text	=> $MBButtonMessage,
			-top	=> $MBHeight * .5,
			-left	=> $MBWidth * .1 + $MBButtonBuffer * $Ctr + $MBButtonWidth * ($Ctr - 1),
			-height	=> $MBButtonHeight,
			-width	=> $MBButtonWidth,
			-font	=> $MBButtonFont,
		);
		$Ctr++;
	}

	local $MBButton;

	sub MBTimeOut_Timer { $MBButton = "Timeout"; return -1; }

	sub MBButton1_Click { $MBButton = $MBButtons[0]; return -1; }

	sub MBButton2_Click { $MBButton = $MBButtons[1]; return -1; }
	
	sub MBButton3_Click { $MBButton = $MBButtons[2]; return -1; }

	sub MBButton4_Click { $MBButton = $MBButtons[3]; return -1; }

	$MsgBox->Show;

	$MsgBox->BringWindowToTop;

	Win32::GUI::Dialog();

	$MsgBox->Show(0);

	$MBTimeOut->Kill();

	return $MBButton;
}


