in reply to Win32 - Where will the focus go?
Even though the LostFocus event handler is called before the GotFocus event handler, the value returned by GetFocus() actually changes just before the LostFocus event. Therefore, your solution should be as simple as calling $your_main_window->GetFocus() inside your LostFocus event handler; it should tell you who is getting the new focus.
I may be wrong about this, but the example code below bears the thought out.
Working, tested code:
use strict; use warnings; use Win32::GUI; $| = 1; # Important! - Turn off buffering my $W1 = Win32::GUI::Window->new( -name => 'W1', -title => 'PerlMonks_494615', -pos => [ 100, 100 ], -size => [ 300, 200 ], ); my $T1 = $W1->AddTextfield( -name => 'T1', -text => '', -left => 10, -top => 10, -width => 200, -height => 25, -prompt => ['T1:', 80], ); my $T2 = $W1->AddTextfield( -name => 'T2', -text => '', -left => 10, -top => 35, -width => 200, -height => 25, -prompt => ['T2:', 80], ); $W1->Show(); print "$_->{-name}\t$_->{-handle}\n" foreach $W1, $T1, $T2; Win32::GUI::Dialog(); sub T1_GotFocus { print "\nT1_GotFocus - ",$W1->GetFocus(), "\n"; } sub T2_GotFocus { print "\nT2_GotFocus - ",$W1->GetFocus(), "\n"; } sub T1_LostFocus { print "\nT1_LostFocus - ",$W1->GetFocus(); } sub T2_LostFocus { print "\nT2_LostFocus - ",$W1->GetFocus(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Win32 - Where will the focus go?
by ChrisR (Hermit) on Sep 23, 2005 at 19:45 UTC | |
by Util (Priest) on Sep 25, 2005 at 22:49 UTC | |
by ChrisR (Hermit) on Sep 26, 2005 at 12:30 UTC |