With python 3, I'd like to get a handle to another window (not part of my application) such that I can either:
a) directly capture that window as a screenshot or
b) determine its position and size and capture it some other way
In case it is important, I am using Windows XP (edit: works in Windows 7 also).
I found this solution, but it is not quite what I need since it is full screen and more importantly, PIL to the best of my knowledge does not support 3.x yet.
Ars gave me all the pieces. I am just putting the pieces together here for anyone else who needs to get a screenshot in python 3.x. Next I need to figure out how to work with a win32 bitmap without having PIL to lean on.
Get a Screenshot (pass hwnd for a window instead of full screen):
Get a Window Handle by title (to pass to the above function):
Here's how you can do it using PIL on win32. Given a window handle (
hwnd
), you should only need the last 4 lines of code. The preceding simply search for a window with "firefox" in the title. Since PIL's source is available, you should be able to poke around theImageGrab.grab(bbox)
method and figure out the win32 code you need to make this happen.