Hi all,
I'm trying to implement a simple error handling subroutine, which pops up
a modal error message during the main Dialog() phase.
My problem is that when I call my subroutine, the modal window appears,
but my script won't wait for me to close it before carrying on. I've had a
bit of a fiddle, but don't want to start hacking when there's more than
likely a function I've overlooked.
See the code below (adapted from the modal window tutorial)
TIA,
Mark
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",
);
$MainWindow->Show();
Win32::GUI::Dialog();
sub showmodal {
$errmsg = shift;
$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 => $errmsg,
);
$MainWindow->Disable();
$ModalWindow->Show();
#Do something here to wait for modal window to be closed.
}
sub OpenModal_Click {
print "Do stuff that generates an error\n";
showmodal("Error message");
print "I want this to happen after the modal dialog is closed\n";
}
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
}