Hi,

I've been playing with the new DoModal window support (it works really well), 
but came across an interesting problem. Imagine a multi window application, 
where each window can open the same dialogue. At the moment you specify the 
parent on window creation, but in this example you need to be able to set the 
parent dynamically (because focus is set back to the parent, not the window 
that opened the dialogue - see the example below). The solution would be to add 
SetParent to the core, but I'm not sure of the implications this would have - 
or for that matter, if it is the correct approach? 

Thoughts anyone?

Cheers,

jez.

=================

use Win32::GUI;
use strict;

#Create 2 main windows
my $Win = new Win32::GUI::Window (
    -pos         => [100, 100],
    -size        => [330, 235],
    -name        => "Window",
    -text        => "Win32::GUI demo",
    -onTerminate => sub {return -1;}
);

$Win->AddButton(
  -name  => 'Open',
  -text  => 'Open',
  -pos         => [20, 20],
  -size        => [50, 20],
  -onClick => \ &OpenModal,
);

my $Win2 = new Win32::GUI::Window (
    -pos         => [200, 200],
    -size        => [330, 235],
    -name        => "Window2",
    -text        => "Win32::GUI demo2",
    -onTerminate => sub {return -1;}
);

$Win2->AddButton(
  -name  => 'Open',
  -text  => 'Open',
  -pos         => [20, 20],
  -size        => [50, 20],
  -onClick => \ &OpenModal,
);

#Create the Dialog Window
my $Dialog = Win32::GUI::DialogBox->new(
   -pos         => [300, 300],
   -size        => [200, 200],
   -name => 'DTB',
   -text => 'Some Dialog',
   #Comment out this line to see the effect of not setting a parent.
   -parent => $Win,
   -onTerminate =>  sub {return -1;},
);

$Dialog->AddButton(
  -name  => 'Close',
  -text  => 'Close',
  -pos         => [20, 20],
  -size        => [50, 20],
  -onClick => sub {return -1;},
);

$Win->Show();
$Win2->Show();
Win32::GUI::Dialog();

sub OpenModal {
  $Dialog->DoModal(1);
}


Reply via email to