Welcome, guest | Sign In | My Account | Store | Cart

This recipe is the Python implementation of the SystemParametersInfoA() invocation required to retrieve the area that application windows can inhabit. On multi-monitor setups, the windows code returns the area on the primary monitor only. This recipe is the cleaned up version of this email post http://mail.python.org/pipermail/python-list/2003-May/162433.html .

Python, 13 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import ctypes

def work_area():
  class RECT(ctypes.Structure):
     _fields_ = [('left',ctypes.c_ulong),
                 ('top',ctypes.c_ulong),
                 ('right',ctypes.c_ulong),
                 ('bottom',ctypes.c_ulong)]
  r = RECT()
  ctypes.windll.user32.SystemParametersInfoA(win32con.SPI_GETWORKAREA, 0, ctypes.byref(r), 0)
  return map(int, (r.left, r.top, r.right, r.bottom))

print work_area()

This recipe requires ctypes from http://starship.python.net/crew/theller/ctypes .