[python-win32] How to take a snapshot of a specific control?

Mark Hammond mhammond at skippinet.com.au
Mon Dec 11 23:53:37 CET 2006


> 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 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

Mark



More information about the Python-win32 mailing list