win32gui.FindWindow not returning correct values

Viewed 883

So I always used this code to find window position/sizes and today I tried to locate the Memu (an android emulator) window.

This code :

def print_memu_position():
    hwnd = win32gui.FindWindow(None, "MEmu")
    left, top, right, bottom = win32gui.GetWindowRect(hwnd)
    print "topleft_xy = {},{}".format(left, top)
    print "bottomright_xy = {},{}".format(right, bottom)
    print "width = {}".format(right-left)
    print "height = {}".format(bottom-top)

prints :

topleft_xy = 3635,881
bottomright_xy = 3714,925
width = 79
height = 44

which is not correct the Memu window is 574x982

I'm using 3 screens but it should not be a problem because when I use this code to find something else, Vysor for example that miror a phone screen on your computer I get correct results.

Here is what was found visually :

enter image description here

Any ideas on how to solve the problem? Thanks

EDIT :

this code does find the MEmu hwnd

def printMemuHwnd():

    def winEnumHandler(hwnd, ctx):
        if win32gui.IsWindowVisible(hwnd):
            if win32gui.GetWindowText(hwnd) == "MEmu":
                print (hex(hwnd), win32gui.GetWindowText(hwnd))
                left, top, right, bottom = win32gui.GetWindowRect(hwnd)
                print "topleft_xy = {},{}".format(left, top)
                print "bottomright_xy = {},{}".format(right, bottom)
                print "width = {}".format(right - left)
                print "height = {}".format(bottom - top)

    win32gui.EnumWindows(winEnumHandler, None)

and with GetForegroundWindow() I get the correct dimension.

so why won't hwnd = win32gui.FindWindow(None, "MEmu") work?

0 Answers
Related