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!


In reply to NVM - was Win32::GUI and widget focus after window focus change by mrider

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.