how calculate the available screen for a window?

David Bolen db3l at fitlinxx.com
Fri May 9 11:43:57 EDT 2003


"Federico" <maschio_77 at hotmail.com> writes:

> how calculate the available screen for a window? I mean the screen
> resolution without the start bar pixels (in windows)

The underlying call you need to make is to SystemParametersInfo using
the SPI_GETWORKAREA parameter.  (As opposed to the GetSystemMetrics
call which can return the total physical screen size)

The win32all package wraps GetSystemMetric but I don't believe it does
SystemParametersInfo at this point.  You can however, call the latter
function fairly easily with something like the calldll or ctypes
(http://starship.python.net/crew/theller/ctypes.html) modules.  Here's
an example using ctypes:

          - - - - - - - - - - - - - - - - - - - - - - - - -
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> SPI_GETWORKAREA=48
>>> class RECT(ctypes.Structure):
...   _fields_ = [('left',ctypes.c_ulong),
...               ('top',ctypes.c_ulong),
...               ('right',ctypes.c_ulong),
...               ('bottom',ctypes.c_ulong)]
...
>>> x = ctypes.windll.user32
>>> r = RECT()
>>> x.SystemParametersInfoA(SPI_GETWORKAREA,0,ctypes.byref(r),0)
1
>>> r.top
c_ulong(0)
>>> r.left
c_ulong(0)
>>> r.bottom
c_ulong(715)
>>> r.right
c_ulong(1024)
>>>
          - - - - - - - - - - - - - - - - - - - - - - - - -

This is on a 1024x768 display where my taskbar is at the bottom of the
screen and is two rows high.

If you don't have local Windows development info (e.g., MSDN, Visual
Studio, a platform SDK) then you can look up this function at
http://msdn.microsoft.com.  However, I think you'd have to have some
SDK - such as the core platform SDK - installed locally for you to
determine the right value for SPI_GETWORKAREA (which is defined in the
WINUSER.H header file).  But it's a free download.

-- David




More information about the Python-list mailing list