I've gone nearly blind looking through the source code, and can't see why I am experiencing the following behaviour. I have examined the windows generated with Spy++, and the modal window has its parent/owner set correctly, and I cannot see how the movement of the modal window before calling DoModal causes a change in behaviour.

Am I using DoModal correctly?  Does anyone else see the same problem.

Regards,
Rob.

# This shows a possible bug where a modal dialog loses its modality
# Try clicking on the close button of the main window after opening
# the modal window - the modal dialog closes, and a second click is
# need to then close the main window.  The main window should
# be disabled.
#.
# If the code to center the dialog is moved to an 'onActivate'
# callback (or removed), then it all works fine.
#
# If the modal window is also a dialog window (-dialogui => 1), then
# it's special navigation features are lost (i.e. tabbing stops working,
# return = OK does not work).
#
# Workarounds:
# (1) Don't Center (or otherwise move the dialog) before calling doModal.
#     I have resolved this by putting the Center() call in an onActivate
#     handler.
# (2) If you only have one top-level window, set the 'all' flag to 1.
#     I.e. $modal->DoModal(1).

use strict;
use warnings;

use Win32::GUI;

my $mw = Win32::GUI::Window->new(
 -title => "doModal() Bug",
 -pos => [100,100],
 -size => [200,200],
);

$mw->AddButton(
 -text => "Open Modal Window",
 -onClick => \&openModal,
);

my $modal = Win32::GUI::Window->new(
 -parent => $mw,
 -title => "Modal Window",
 -size => [100,100],
);

$mw->Show();
Win32::GUI::Dialog();
exit(0);

sub openModal
{
 # Comment out this next line to see correct behaviour
 $modal->Center($mw);

 $modal->DoModal();

 return 1;
}

Reply via email to