"Robert May" <[EMAIL PROTECTED]> wrote:
Do you have a multi-line edit control (Win32::GUI::Textfield) in the
dialog? Does this symptom only occur when the textfield has focus?
If so it's a known bug - I can generate a work around, let me know.
Teddy wrote:
Hmm, strange! I was almost sure that this issue happends randomly, no
matter
if that multiline control has the focus or not.
(The program do has a multiline readonly textfield)
But I have tested for a few times, and I see that this error appears
only
when that control has the focus.
Please tell me how to solve it.
Jamal Mazrui wrote:
> Rob may have a better solution, but in case it's helpful, this
> technique worked for me. Set Escape as an accelerator key
> that terminates the dialog, e.g., by defining an accelerator
> table as follows:
>
> my $Keyboard = Win32::GUI::AcceleratorTable->new(Escape => sub {return
> -1;});
>
> Then, include
> -accel => $Keyboard
> in the method that creates the dialog window.
In looking into this further, I see that default-button activation with
the RETURN key also doesn't work properly when the focus is in a
multi-line edit control. Here's a generalised work around for both
issues. It work with the latest 1.03_04 release - it'll need a little
tweaking (with respect the constants) to work with earlier versions.
Regards,
Rob.
#!perl -w
use strict;
use warnings;
# Script showing a way of fixing up a multi-line edit control
# so that ESC and RETURN/ENTER keys are handled correctly
# in dialog windows
use Win32::GUI 1.03_04, qw( WM_GETDLGCODE WM_KEYDOWN WM_CHAR
VK_ESCAPE VK_RETURN VK_CONTROL
GWL_STYLE ES_WANTRETURN
);
sub DLGC_HASSETSEL() { 0x0008 }
my $mw = Win32::GUI::DialogBox->new(
-size => [ 400, 300 ],
-title => "Stop ESC",
);
$mw->AddTextfield(
-name => 'TF',
-pos => [ 10, 10 ],
-size => [ 200, 200 ],
-multiline => 1,
-wantreturn => 1,
-tabstop => 1,
);
$mw->TF->Hook( WM_GETDLGCODE, \&fixDlgCode );
$mw->AddButton(
-text => "Exit",
-pos => [ 10, 220 ],
-tabstop => 1,
-default => 1,
-ok => 1,
-onClick => sub { -1 },
);
$mw->Show();
Win32::GUI::Dialog();
$mw->Hide();
exit(0);
sub fixDlgCode {
my ( $win, $wParam, $lParam, $type, $msgcode ) = @_;
return 1 unless $type == 0;
return 1 unless $msgcode == WM_GETDLGCODE;
# $lParam is a pointer to a MSG structure, or NULL:
if ($lParam) {
my ( $m_hwnd, $m_msgcode, $m_wParam, $m_lParam, $m_time, $m_x,
$m_y ) =
unpack( "LLLLLLL", unpack( "P28", pack( "L", $lParam ) ) );
if ( $m_msgcode == WM_KEYDOWN or $msgcode == WM_CHAR ) {
# Tell IsDialogMessage that Edit control doesn't
# want the ESC key
if ( $m_wParam == VK_ESCAPE ) {
$win->Result(DLGC_HASSETSEL);
return 0;
}
# If the Edit control doesn't want the return key
# then tell IsDialogMessage that Edit control doesn't
# want it
# if RETURN or ENTER key pressed ...
if ( $m_wParam == VK_RETURN ) {
# and the shift key is not pressed ...
if ( !Win32::GUI::GetKeyState(VK_CONTROL) ) {
# and the Edit control doesn't want RETURN/ENTER
if ( !( $win->GetWindowLong(GWL_STYLE) &
ES_WANTRETURN ) ) {
$win->Result(DLGC_HASSETSEL);
return 0;
}
}
}
}
}
return 1; # Do default processing
}
__END__