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

Re: [pygame] Picking monitor...



On Fri, Aug 28, 2009 at 10:08 AM, Gene Buckle <geneb@xxxxxxxxxxxxx> wrote:
The main issue is that the avionics computer will have more than a couple of these USB video adapters.  Is it possible to discover the current window position from within pygame?  That would allow me to manually position the window and then "save" the current position as the start position.

Hey Gene,
   stuff like that is always possible - and ctypes is usually the best way to do little hack stuff like this in python.

For getting the window pos, the function "pygame.display_get_info" gives you a dictionary with "window" set the HWND of your window, and the OS function "GetWindowRect" can be called on that HWND to get the window position/size

The code below is getting the pygame window's position just fine for me on windows:
---------------------
import pygame

from ctypes import POINTER, WINFUNCTYPE, windll, WinError
from ctypes.wintypes import BOOL, HWND, RECT
_prototype = WINFUNCTYPE(BOOL, HWND, POINTER(RECT))
_params = (1, "hwnd"), (2, "lprect")
GetWindowRect = _prototype(("GetWindowRect", windll.user32), _params)
def _errcheck(result, func, args):
    if not result:
        raise WinError()
    return args
GetWindowRect.errcheck = _errcheck

def GetPygameWindowPos():
    info = pygame.display.get_wm_info()
    window_id = info["window"]
    r = GetWindowRect(window_id)
    return (r.left, r.top, r.right, r.bottom)
   
pygame.display.set_mode((400,400))
print GetPygameWindowPos()