Screenshot an application, regardless of what's in front of it?

python, screenshot, windows

Solution

I posted working code in the answer here: Screenshot of inactive window PrintWindow + win32gui. It uses the `PrintWindow` function. This is the "correct" way to copy the image of a hidden window, but that doesn't mean that it will always work. It depends on the program implementing the proper message, `WM_Print` response.

If you try to use `PrintWindow` it doesn't work, then your only remaining option would be to bring the window to the front before taking a `BitBlit`.

Problem

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.

Original source

Related problems