#!perl -w
use strict;
use warnings;

use Win32::API;
use Win32::GUI qw(WS_CAPTION);

my $SetWindowPos = Win32::API->new("user32","SetWindowPos", "LLLLLLL", "L")
    or die "Failed to load SetWindowPos";

sub TME_HOVER() {1}
sub TME_LEAVE() {2}
sub HOVER_DEFAULT() {0xFFFFFFFF}
sub SWP_FRAMECHANGED() {32}
sub SWP_NOMOVE() {2}
sub SWP_NOSIZE() {1}
sub SWP_NOZORDER() {4}
sub SWP_NOACTIVATE() {16}

my $state = 0; # 0 - out; 1 - in;

my $mw = Win32::GUI::Window->new(
	-title => "MouseOver/Out & Title Remove",
	-pos => [100,100],
	-size => [400,300],
	-onMouseOver => sub {print "Hover\n"; return 0;},
	-onMouseOut  => \&Out,
	-onMouseMove => \&Move,
	-onTimer => \&otTimer,
);

my $ot = $mw->AddTimer("ot", 10000); # Remove the titlebar in 10 seconds

$mw->Show();
Win32::GUI::Dialog();
exit(0);

sub otTimer
{
    print "Timer expired\n";
    $ot->Interval(0); # Turn off the timer

# Remove the titlebar
    $mw->Change(-popstyle => WS_CAPTION);
    $SetWindowPos->Call($mw->{-handle}, 0, 0, 0, 0, 0,
			SWP_FRAMECHANGED|SWP_NOMOVE|
			SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER);
}

sub Out
{
    print "Out\n";
    $state = 0;
# The mouse has left the window, so remove the title bar in 10 seconds
    $ot->Interval(10000);
    return 0;
}

sub Move
{
	return unless $state == 0;
# The mouse is in the window, stop the timer
	$ot->Interval(0);
# Restore the titlebar
	$mw->Change(-pushstyle => WS_CAPTION);
	$SetWindowPos->Call($mw->{-handle}, 0, 0, 0, 0, 0,
			    SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE|
			    SWP_NOACTIVATE|SWP_NOZORDER);
	print "In\n";
	$state = 1;
	$mw->TrackMouse(1000,TME_HOVER|TME_LEAVE);
	return 1;
}
