"Octavian Rasnita" originally wrote
I am trying to create a multiline textfield on a window that has
the -dialogui option set but the big problem is that I cannot move the
focus out of that window by pressing the tab key.
I've tracked down the problem and have added a solution for the next
release. In the meantime, here's a work around. It doesn't quite work
(you can't enter tab's into the Textfield using ctrl-tab), but may still
be useful?
#!perl -w
use strict;
use warnings;
use Win32::GUI qw(ES_WANTRETURN WS_BORDER WS_EX_NOPARENTNOTIFY WM_KEYDOWN);
sub WM_GETDLGCODE() {0x0087};
sub VK_TAB() {0x09}
sub VK_CONTROL() {17}
my $mw = Win32::GUI::Window->new(
-title => "Tab Navigation",
-pos => [100,100],
-size => [400,300],
-dialogui => 1,
);
my $tf = $mw->AddTextfield(
-size => [200,200],
-tabstop => 1,
-multiline => 1,
-autovscroll => 0,
-vscroll => 1,
-addstyle => ES_WANTRETURN, # allow <enter> to start new line
);
$tf->Hook(WM_GETDLGCODE, \&getcode);
$mw->AddButton(
-pos => [220,220],
-text => "OK",
-default => 1,
-ok => 1,
-tabstop => 1,
);
$mw->AddButton(
-pos => [260,220],
-text => 'Cancel',
-cancel => 1,
-tabstop => 1,
);
$mw->Show();
Win32::GUI::Dialog();
exit(0);
sub getcode
{
my ($object, $wParam, $lParam, $type, $msgcode) = @_;
return unless $type == 0;
return unless $msgcode == WM_GETDLGCODE;
# ignore system queries
return 1 if $lParam == 0;
# unpack the bits of msg structure pointed to by lparam
# that we need
my (undef, $message, $vkey) =
unpack("LLL", unpack("P12", pack("L", $lParam)));
# Not a keydown event, ignore
return 1 unless $message == WM_KEYDOWN;
# Not TAB key, ignore
return 1 unless $vkey == VK_TAB;
# Ctrl key down, ignore - not working
# return 1 if Win32::GUI::GetAsyncKeyState(VK_CONTROL);
# returning 0 (we don't the message)
return 0;
}
__END__
Regards,
Rob.
--
Robert May
Win32::GUI, a perl extension for native Win32 applications
http://perl-win32-gui.sourceforge.net/