use strict;
use Win32::GUI;

my $M = new Win32::GUI::Menu(
  "&Menu"	=> "menu",
    " > &Exit"	=> "exit",
);

my $W = new Win32::GUI::Window(
  -name   	=> "main",
#  -text   	=> "Test",
  -title        => "Test",
  -left   	=> 100,
  -top    	=> 100,
  -width  	=> 400,
  -height 	=> 300,
  -menu   	=> $M,
);

my $EC = new Win32::GUI::Class(     # Without this RichEdit KeyPress Event doesn't get called
   -name => "MyPerlRichEditClass",
   -extends => "RichEdit",
   -widget => "RichEdit",
);


$W->AddRichEdit(
    -class   => $EC,
    -name    => "Console",
    -text    => "",
    -left    => 5,
    -top     => 5,
    -multiline => 1,
    -width   => $W->ScaleWidth-10,
    -height  => $W->ScaleHeight-10,
    -exstyle  => WS_EX_CLIENTEDGE,
    -style    => WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL
                 | ES_LEFT | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
);

$W->Console->SetFocus();
$W->Console->SendMessage(1093, 0, 1);  # Enables Change Event for RichEdit control

$W->Show();
Win32::GUI::Dialog();

#

sub Console_Change {
  print "Change\n";
  return 1;
}

sub Console_KeyPress {
   my($key) = @_;

  print $key."\n";
  if ($key == 13) {
    print "Enter pressed";
  }
  else {
    print "Key $key pressed\n";
  }
}

sub exit_Click {
  return -1;
}

sub main_Terminate {
  return -1;
}