App object with Windows 7

Asked by sylvain caillet

Hi,

I have written a piece of code to get in global variable the active window region using the App object.

def alaloopGetActiveWindow(wmin, hmin, imgTitle=None):
 global app, appWindow

 # get the visible application window
 appWindow=None
 for i in range(100):
  appWindow = app.window(i)
  if not appWindow: break
  log("Get window %i at %i-%i with w=%i - h=%i" % (i, appWindow.x, appWindow.y, appWindow.w, appWindow.h))
  if (appWindow.w < wmin or appWindow.h < hmin): continue

  # check for image in title
  if imgTitle is not None:
   reg=alaloopSelectRegion("TOP", 50, 0, appWindow)
   if not reg.exists(imgTitle, 0): continue

  log("The Window match !")
  break

 if not(appWindow) or appWindow is None:
  popup("Unable to find the active window of application")
  return

It works fine on Windows XP SP2. For example with Notepad++, it's easy to get the main window, or the "open file" window or the "search" window.
But the same script on a Windows 7 can't find anything else than some 0 sized windows.

Do you know anything about such a trouble ?

Thank you for your help,

Sylvain Caillet

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

I testted your script with the following main workflow

app =App(r"C:\Program Files\Notepad++\notepad++.exe")
app.focus()
wait(5)
type("f", KEY_CTRL); wait(2)
alaloopGetActiveWindow(200,200,"Find")

on my Win7 32Bit.

This seems to generally only work if Notepad++ does not run, so it is started by the script.

So I doubt, you will not get to your target with the current implementation of the App class.
For running apps, you need to know at least part of the window title.

App.focusedWindow() seems to work, but it does not "tell" you the app it belongs to.

I have no idea.

Revision history for this message
sylvain caillet (scaillet) said :
#2

Ok, thank you for your message. I didn't know the App.focusedWindow() function and now, my functions are ok with it.

Revision history for this message
sylvain caillet (scaillet) said :
#3

Thanks RaiMan, that solved my question.