[python-win32] How to take a snapshot of a specific control?
Ray Schumacher
rays at blue-cove.com
Tue Dec 12 01:35:24 CET 2006
At 02:53 PM 12/11/2006, Mark Hammond wrote:
> These lines all execute:
> dtwnd = win32gui.GetDesktopWindow()
> hdcSrc = win32gui.GetWindowDC(dtwnd)
> hdcDestH = win32ui.CreateDCFromHandle(dtwnd)
The last line above is a problem - try something like hdcDestH =
win32gui.GetDC(dtwnd)
> hdcDest = win32gui.CreateCompatibleDC(hdcSrc)
> hBitmap = win32gui.CreateCompatibleBitmap(hdcSrc, 1024, 768)
> win32gui.SelectObject(hdcDest, hBitmap)
> destHDC = hdcDestH.GetSafeHdc()
>
> but I start having trouble with
> hdcDestH.BitBlt((0, 0), (1024, 768), hdcSrc, (0, 0),
0x00CC0020)
> TypeError: The 'O' param must be a PyCDC object
> and on from there.
Then you want something like win32gui.BitBlt(hdcDestH, (0,0), ...)
I did a dir(win32gui) and BitBlt was not there! i had tried before,
and so was mystified - I had ActivePython 2.4.1 Build 245, and just
upgraded to 2.4.3, and now have BitBlt()
I found some code at
http://trac.browsershots.org/browser/trunk/shotfactory/lib/gui/windows.py?rev=585
import win32gui
import win32con
from time import time as t
t0=t()
hDC = win32gui.GetWindowDC(0)
memDC = win32gui.CreateCompatibleDC(hDC)
memBM = win32gui.CreateCompatibleBitmap(hDC, 1024, 768)
win32gui.SelectObject(memDC, memBM)
win32gui.BitBlt(memDC, 0, 0, 1024, 768, hDC, 0, 0, win32con.SRCCOPY)
t()-t0
But, the timer gives .57seconds !
even slower than PIL's ImageGrab Module :-(
win32gui.StretchBlt(memDC, 0, 0, 1024, 768, hDC, 0, 0, 640, 480,
win32con.SRCCOPY)
is .25 seconds, a bit better.
Whole screen caps do seem a bit slow, so it looks like StretchBlt on
subregions that are modified are required.
It doesn't look like it can be done quickly, without the VNC
dependant py packages or the Media 9 Screen codec
> I can't say that I need anything from win32ui, since I don't know
> what I need at all!
In the above, you are using win32ui.CreateDCFromHandle() - and given
what I
said in the last mail, you probably want to try and find win32gui
operations instead of win32ui ones
I was trying the kitchen sink...
Best, and thanks for the help,
Ray
More information about the Python-win32
mailing list