SourceForge has been redesigned. Learn more.
Close

#34 DoModal is not always Modal

closed-fixed
nobody
None
1
2005-11-22
2005-03-17
Robert May
No

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;
}

Discussion

  • Robert May

    Robert May - 2005-10-05

    Logged In: YES
    user_id=674651

    It turns out that the Win32 api call GetParent does not
    always return an owner window, despite the reference
    documentation not mentioning this. See
    http://support.microsoft.com/default.aspx?scid=kb;en-us;84190

    As a result the DoModal Implementation was using the active
    window, which is changed by calling Center() ...

    Fix is in CVS and should make it into the next release.

    Rob.

     
  • Robert May

    Robert May - 2005-10-05
    • priority: 5 --> 1
    • status: open --> open-fixed
     
  • Robert May

    Robert May - 2005-11-22
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.