JGX020/dragonfly

Focus window command doesn't bring it to the foreground

Closed this issue · 3 comments

What steps will reproduce the problem?
1. I installed the window control plug in.
2. I used name window foo to set a name.
3. From another window I said focus window foo.

What is the expected output? What do you see instead?
Window foo should have come to the foreground but it only started blinking 
in the taskbar and didn't pop up.

What version of the product are you using? On what operating system?
Windows 7 64 bit
Python 2.6 32 bit
Natlink 3.9 charlie beta
Dragonfly 0.6.5

Thanks!

Original issue reported on code.google.com by dbenamy on 25 Mar 2010 at 4:03

I just noticed the following in my natlink message log:

rule: FocusWinRule(FocusWinRule): set_foreground() failed: (183, 
'SetForegroundWindow', 
'Cannot create a file when that file already exists.').

Original comment by dbenamy on 25 Mar 2010 at 4:17

Windows has a setting which will allow one process to control the windows of 
another
process.  This is what your Dragonfly command-module is trying to do.

From Windows Vista on this is by default not possible.  However, this setting 
can
easily be changed to make it possible.  Attached is a very small script which 
enables
a process to control another's windows.  Please run it and let us know whether 
it
solves your problem.

(Note the horrible error message the Windows API function returned in the first
comment above...)

Original comment by ct.butcher@gmail.com on 6 May 2010 at 4:04

  • Changed state: Done
  • Added labels: Type-Other
  • Removed labels: Type-Defect

Attachments:

actually, this fix doesn't work. I have found the solution, finally! It is 
discussed here:

http://www.asyncop.com/MTnPDirEnum.aspx?treeviewPath=[o]+Open-Source\WinModules\
Infrastructure\SystemAPI.cpp

under the ForceForegroundWindow() function.

fortunately, this has already been implemented in pywinauto. The relevant lines 
are:

                 wh = WrapHandle(ao.Window) 
                 wh.SetFocus()
                 win32functions.AttachThreadInput(win32functions.GetCurrentThreadId(), wh.ProcessID(), 1)

with

from pywinauto.controls import WrapHandle
from pywinauto import win32functions

I've been testing this for about a week and it seems to work!

Good luck!




Original comment by recko...@gmail.com on 22 Feb 2011 at 4:19