So I can use PIL to grab a screenshot of the desktop, and then use pywin32 to get its rectangle and crop out the part I want. However, if there's something in front of the window I want, it'll occlude the application I wanted a screenshot of. Is there any way to get what windows would say an application is currently displaying? It has that data somewhere, even when other windows are in front of it.
views:
336answers:
5
A:
IIRC, not in Windows pre-vista - with Aero each window has it's own buffer, but before that, you would just use your method, of getting the rectangle. I'm not sure if pywin32 has Aero support or not.
Lucas Jones
2009-07-03 20:28:31
+1
A:
If you can, try saving the order of the windows, then move your app to the front, screenshot, and move it back really quickly. Might produce a bit of annoying flicker, but it might be better than nothing.
Mark
2009-07-03 20:33:26
yeah, unless there's a specialized function that can take a specific screenshot, that's how I'd do it too.
Geo
2009-07-03 20:38:59
+1
A:
I've done the same thing by giving the application I want focus before taking the shot:
shell=win32com.client.Dispatch("Wscript.Shell")
success = shell.AppActivate(app_name) # Returns true if focus given successfully.
Kiv
2009-07-03 21:13:01
A:
Maybe you can position the app offscreen, then take the screenshot, then put it back?
Luke Stanley
2009-08-13 05:03:47
A:
There is a way to do this, using the PrintWindow
function. It causes the window to redraw itself on another surface.
Claudiu
2010-08-27 16:01:46