#!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}
sub MF_BYCOMMAND() {0}

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

my $menu = Win32::GUI::MakeMenu(
				"&File" => "File",
				" > E&xit" => "menu_exit",
				);

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

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);
# Remove the menu
    $mw->SetMenu(0);
}

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;
    print "In\n";
    $state = 1;
    $mw->TrackMouse(250,TME_HOVER|TME_LEAVE);
    return 1;
}

sub Hover
{
    print "Hover\n";
# 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);
# Restore the menu
    $mw->SetMenu($menu);
    return 0;
}

sub menu_exit_Click
{
    return -1;
}

