[python-win32] Screenshot a given window instead of the whole desktop

Tim Roberts timr at probo.com
Mon May 1 02:12:44 EDT 2017


On Apr 28, 2017, at 5:40 PM, Michael C <mysecretrobotfactory at gmail.com<mailto:mysecretrobotfactory at gmail.com>> wrote:

I have my own code that samples pixel colour,
https://pastebin.com/4EMd765h

 and now I am trying to add the feature of saving the Device Context to a .bmp file, so I found this code

https://books.google.ca/books?id=9MS9BQAAQBAJ

however there is one problem: The book example screenshots the whole desktop and I only want a screenshot of a given window. Is there a way to modify the black hat example into something that only screenshot a window given its handle?

It would have been easier to help if you had showed us the code you're trying to modify.

I assume the code you're copying does GetDC(0) to grab a DC for the desktop.  If you instead pass the window handle of the window you want to snapshot, just pass that to GetDC.  You'll want to use GetWindowRect to find the size of the window.
—
Tim Roberts, timr at probo.com<mailto:timr at probo.com>
Providenza & Boekelheide, Inc.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20170430/a07292a2/attachment.html>


More information about the python-win32 mailing list