Mark,

Your problem is much like one that I required a solution to, so using
the example below I attempted a number of different resolutions,
threads, api calls, process calls, in the end the resolution was much
more straight forward.

# Counts to 25 with an "error" at 20
# Perl v5.8.4 built for MSWin32-x86-multi-thread
# Win32-GUI               [1.0] Perl-Win32 Graphical User Interface
Extension

use Win32::GUI;
use strict;

my $MainWindow = Win32::GUI::Window->new(
        -text => "Main",
        -name => "MainWindow",
        -pos  => [ 200, 200 ],
        -size => [ 150, 100 ],
);

$MainWindow->AddButton(
        -name => "OpenModal",
        -pos  => [ 15, 20 ],
        -text => "Count to 25",
);
# Moved the Modal window and button outside the sub
my $ModalWindow = Win32::GUI::Window->new(
        -text => "Modal",
        -name => "ModalWindow",
        -pos  => [ 220, 220 ],
        -size => [ 150, 100 ],
        -parent => $MainWindow,
);
my $ModalButton = $ModalWindow->AddButton(
        -name => "CloseModal",
        -pos  => [ 15, 20 ],
        -text => "dummyvaldummyval",
);
my $forgotten_value     = undef;

$MainWindow->Show();
Win32::GUI::Dialog(); # This is the main dialog sequence

sub OpenModal_Click {
        $MainWindow->Disable();
        for (my $i=0; $i <= 25; $i++){
                if ($i == 20) {
                        showmodal("Where was I again\?");
                }
                print $i."\n";
        }
        $MainWindow->Enable();
        $MainWindow->BringWindowToTop();
}
sub MainWindow_Terminate {
        -1;
}
sub showmodal {
        $ModalButton->Change(-text => @_,);

        $ModalWindow->Show();
        Win32::GUI::Dialog(); # This dialog sequence is specific to the
modal window
}
sub CloseModal_Click {
        ModalWindow_Terminate();
}
sub ModalWindow_Terminate {
        $forgotten_value = 20;
        $ModalWindow->Hide();
        return -1; # This will terminate the modal window dialog
sequence the main dialog sequence will still remain
}


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Mark Nettlingham
Sent: Tuesday, November 30, 2004 6:34 AM
To: perl-win32-gui-users@lists.sourceforge.net
Subject: [perl-win32-gui-users] Awaiting modal window closure

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 }





-------------------------------------------------------
SF email is sponsored by - The IT Product Guide Read honest & candid
reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users 
  
       This message may contain privileged and/or confidential information.  If 
you have received this e-mail in error or are not the intended recipient, you 
may not use, copy, disseminate or distribute it; do not open any attachments, 
delete it immediately from your system and notify the sender promptly by e-mail 
that you have done so.  Thank you. 
 

Reply via email to