Hi all,

I want to write an editor use Win32::GUI;
So I hope I can process the KeyDown event for Textfield control by myself.
After some tries,
I can't disable the default action of Textfield in sub onKeyDown().

following is my code, any help would be appreciated.

#! perl -w

use strict;
use Win32::GUI;
use Data::Dumper;

my $CurrentFile = "";

my $EditFont = new Win32::GUI::Font (
        -name => "Fixedsys",
        -size => 12,
   );

# Create Main Window
our $Window = new Win32::GUI::Window (
   -name     => "Window",
   -title    => "Notepad",
   -pos      => [100, 100],
   -size     => [400, 400],
   -onResize   => \&Notepad_OnSize,

) or die "new Window";

my $count = 0;

# Create Textfield for Edit Text
$Window->AddTextfield(
   -name      => "Edit",
   -pos       => [0, 0],
   -size      => [100, 100],
   -multiline => 1,
   -hscroll   => 1,
   -vscroll   => 1,
   -autohscroll => 1,
   -autovscroll => 1,
   -keepselection => 1 ,
   -font => $EditFont,
   -onKeyDown => sub {
       my $key = $_[2];
       $Window->{StatusBar}->SetText( 0, sprintf( "value = [%d], char
= [%c], count = [%d]", $key, $key, $count++ ) );
       -1;
   },
);

$Window->AddStatusBar(
   -name => 'StatusBar',
);

# Set Focus to Edit and show Window
$Window->Edit->SetFocus();
$Window->Show();

Win32::GUI::Dialog();

#######################################################################
#  Window Event

# Resize Window
sub Notepad_OnSize {
 my ($self) = @_;
 my ($width, $height) = ($self->GetClientRect())[2..3];
 $self->Edit->Resize($width, $height-20) if exists $self->{Edit};
 $self->StatusBar->Resize($width, $height) if exists $self->{StatusBar};
}
__END__

Reply via email to