[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Re: Query Pygame window position after creation?



So, I can partly reply to my own post:  I found a way to do this on Windows (shown below).  But I realize this returns the location of the window, I need to know the location of the display screen (pygame surface).  The values this returns are the outer window extents, including title-bar, outer window frame, and these can vary based on the UI.  So.... I guess I should re-ask my question:

For a given Pygame surface, how can I query its position in the screen (computer screen, not pygame display)

from ctypes import POINTER, WINFUNCTYPE, windll
from ctypes.wintypes import BOOL, HWND, RECT

# get our window ID:
hwnd = pygame.display.get_wm_info()["window"]

# Jump through all the ctypes hoops:
prototype = WINFUNCTYPE(BOOL, HWND, POINTER(RECT))
paramflags = (1, "hwnd"), (2, "lprect")
GetWindowRect = prototype(("GetWindowRect", windll.user32), paramflags)

# finally get our data!
rect = GetWindowRect(hwnd)
print "top, left, bottom, right: ", rect.top, rect.left, rect.bottom, rect.right
# bottom, top, left, right: 644 98 124 644