Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Win32::GuiTest Get Window Focus

by PyrexKidd (Monk)
on Mar 10, 2011 at 10:06 UTC ( [id://892379]=perlquestion: print w/replies, xml ) Need Help??

PyrexKidd has asked for the wisdom of the Perl Monks concerning the following question:

How do I determine the window handle of the window that has focus, that is not a child of the Perl process? I thought this would work, but it returns 0 for all windows except the window generated by the perl process.

use 5.010001; my $hwnd = GetDesktopWindow(); my $focus_id = GetFocus($hwnd); say $focus_id;

Though I don't think it makes a difference, I am using Wx to generate a window and a timer event to poll the environment for the window with focus.

Thanks.

Replies are listed 'Best First'.
Re: Win32::GuiTest Get Window Focus
by Corion (Patriarch) on Mar 10, 2011 at 10:41 UTC

    If you want to know the active window, have you tried Win32::GuiTest::GetActiveWindow(0)? This should be fairly equivalent to GetFocus(0), but I haven't tried either.

Re: Win32::GuiTest Get Window Focus
by Anonymous Monk on Mar 10, 2011 at 10:36 UTC
    A windows, which is not visible, cannot have focus -- you will have to minimize all other visible windows, minus any belonging to the taskbar -- there is an API call for that

      That's not entirely true.

      I've seen at least two poorly written programs, in which a modal dialog box ends up with the focus, but is behind another window.

      You can't move the obscuring window because the dialog has to be dealt with first, and you can't complete the dialog because the window is in the way...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://892379]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-18 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found