to my absolute dismay, I've just discovered that "true" modal windows
are perfectly doable in Win32::GUI.
I banged my head for more than one week fighting with dialog templates
and crappy hacks... what a fool.
the following code implements a regular modal window, with all the
features. the trick is in the "-parent" option, and proper use of
Enable/Disable, Show/Hide and BringWindowToTop.
use Win32::GUI;
$MainWindow = Win32::GUI::Window->new(
-text => "Main",
-name => "MainWindow",
-pos => [ 200, 200 ],
-size => [ 150, 100 ],
);
$MainWindow->AddButton(
-name => "OpenModal",
-pos => [ 15, 20 ],
-text => "Open Modal Window",
);
$ModalWindow = Win32::GUI::Window->new(
-text => "Modal",
-name => "ModalWindow",
-pos => [ 220, 220 ],
-size => [ 150, 100 ],
-parent => $MainWindow, # this is the trick!
);
$ModalWindow->AddButton(
-name => "CloseModal",
-pos => [ 15, 20 ],
-text => "Close Modal Window",
);
$MainWindow->Show();
Win32::GUI::Dialog();
sub OpenModal_Click {
$MainWindow->Disable();
$ModalWindow->Show();
}
sub CloseModal_Click {
$ModalWindow->Hide();
$MainWindow->Enable();
$MainWindow->BringWindowToTop();
return 1;
}
sub MainWindow_Terminate {
-1;
}
sub ModalWindow_Terminate {
CloseModal_Click();
return 0; # so that $ModalWindow is not destroyed
}
maybe all this can be encapsulated in Perl functions, like this:
sub OpenModal_Click {
$MainWindow->DoModal($ModalWindow);
}
sub CloseModal_Click {
$ModalWindow->EndDialog();
}
would this fulfill all the needs for modal dialog boxes?
cheers,
Aldo
__END__
$_=q,just perl,,s, , another ,,s,$, hacker,,print;