[python-win32] win32gui, win32ui -- how to release references?

Marcus Goldfish magoldfish at gmail.com
Mon Mar 21 05:56:33 CET 2005


As an addendum to my previous post: I was able to successfully do
screen capturing using win32gui + win32ui, [though I am still looking
for a solution that works without win32ui].  The code goes something
like:
 
   l, t, r, b = win32gui.GetWindowRect(hwnd)
   h, w = b-t, r-l
   hDC = win32gui.GetDC(hwnd)
   tmpDC = win32ui.CreateDCFromHandle(hDC)
   myDC = tmpDC.CreateCompatibleDC()
   myBitmap = win32ui.CreateBitmap()
   myBitmap.CreateCompatibleBitmap(tmpDC, w, h)
   myDC.SelectObject(myBitmap)
   myDC.BitBlt((0,0), (w,h), tmpDC, (0,0), win32con.SRCCOPY)
   myBitmap.Paint(newDC)
 
   # process bitmap
 
   # cleanup
 
In the C/C++ code snippets I've seen, the cleanup step usually
involves ReleaseDC(hwnd, hDC), DeleteDC(myDC), and
DeleteObject(myBitmap).  Are these steps automatically handled in
Python by win32gui and win32ui?  If not, can someone post a snippet of
cleanup code that works for this example?
 
Thanks!
Marcus


More information about the Python-win32 mailing list