Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

NVM - was Win32::GUI and widget focus after window focus change

by mrider (Sexton)
on Aug 29, 2012 at 17:03 UTC ( #990510=perlquestion: print w/ replies, xml ) Need Help??
mrider has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks!

I've tried Googling for this as well as reading through the Win32-GUI documentation, but haven't found anything. Here's my issue: I have a Win32::GUI dialog with a few widgets. When I Alt Tab away from the dialog and then Alt Tab back, the widget which previously had focus loses it. Additionally, it appears as if nothing inside the dialog has focus, and that focus can't be regained directly from the keyboard without an accelerator (i.e. multiple presses of "Tab" does not move back to a widget).

I'm considering having a variable with dialog global scope that stores a reference to a widget, and then I can add a event handler in each widget that puts itself into that variable when a given widget gains focus. I could then have a focus listener on the dialog which restores focus to the widget as reflected by the variable when the dialog itself regains focus.

But before I do all that, I want to see if there's something simple I'm missing. So basically is there a better way than storing the widget which previously had focus and then restoring it?

#perl -w #---------- SSCCE ---------- use strict; use Win32::GUI(); use constant WINDOW_WIDTH => 100; use constant WINDOW_HEIGHT => 100; my $main = Win32::GUI::DialogBox( -name => "Main", -text => "SSCCE", -helpbutton => 0, ); my $field = $main->AddTextfield( -name => "TestField", -pos => [10, 10], -size => [WINDOW_WIDTH - 20, 20], -align => "left", ); $main->Resize(WINDOW_WIDTH, WINDOW_HEIGHT); $main->Show(); Win32::GUI::Dialog();
TIA

EDIT: I should add that to demonstrate my problem, run the SSCCE, place the cursor inside the text field, Alt-Tab away from the dialog, and then Alt-Tab back. See how the field does not have focus? Also see how multiple presses of Tab will not put it back?

EDIT 2: Well, don't I feel dumb. From Win32::GUI::Tutorial::Part3 keyboard handling:

"To make the tab keys work as expected, you need to add the -tabstop => 1 option to your controls. The tab keys move the focus between the controls with the -tabstop option set. Other controls will be ignored when tabbing."

Thanks anyway!

Comment on NVM - was Win32::GUI and widget focus after window focus change
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://990510]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2014-11-23 16:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (134 votes), past polls