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( { Message=>"Hello World.", TimeOut=>5 } ); 

	return 1; 
}


$Window->Show;

$Window->BringWindowToTop;

Win32::GUI::Dialog();

exit;



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

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

	my ($DefMBWidth, $DefMBHeight, $DefBTNWidth, $DefBTNHeight, $DefTimeOut) = (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 $DefTimeOut);

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

	my ($BTNWidth, $BTNHeight) = @{$$MessageProps{ButtonSize}} ? @{$$MessageProps{ButtonSize}} : ($DefBTNWidth, $DefBTNHeight);

	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 $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 $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 $TimeOut = $MsgBox->AddTimer("TimeOut", $TimeOut * 1000);

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

	my $Ctr = 1;
	my $BTNMessage;
	my %BTN;
	foreach $BTNMessage ( @MBButtons )
	{
		my $BTNBuffer = ($MBWidth * .8 - ( $BTNWidth * ($#MBButtons + 1) ) ) / ($#MBButtons + 2);
 
		$BTN{$BTNMessage} = $MsgBox->AddButton
		(
			-name	=> "Button$Ctr",
			-text	=> $BTNMessage,
			-top	=> $MBHeight * .5,
			-left	=> $MBWidth * .1 + $BTNBuffer * $Ctr + $BTNWidth * ($Ctr - 1),
			-height	=> $BTNHeight,
			-width	=> $BTNWidth,
			-font	=> $BTNFont,
		);
		$Ctr++;
	}

	local $MBButton;

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

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

	sub Button2_Click { $MBButton = $MBButtons[1]; return -1; }
	
	sub Button3_Click { $MBButton = $MBButtons[2]; return -1; }

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

	$MsgBox->Show;

	$MsgBox->BringWindowToTop;

	Win32::GUI::Dialog();

	$MsgBox->Show(0);

	$MsgBox->Destroy;

	return $MBButton;
}


