"Rune Strand" <ru*********@gm ail.com> wrote in message news:11******** **************@ y43g2000cwc.goo glegroups.com.. .
Is it possible by use of pyWin32 or ctypes to make a screen capture of
an inactive, or a hidden window if the hwnd/WindowName/ClassName is
known? I've seen dedicated screen capture software do this. While
PIL.ImageGrab.g rab() is excellent, it will only capture the foreground
of the desktop. I've tried for hours, but I soon get helplessly lost in
the labyrinths of the Win32API.
This will restore a minimized window, bring it to the top and save a bmp.
import time
import win32gui, win32ui, win32con, win32api
def window_capture( window_title):
hwnd=win32gui.F indWindow(None, window_title)
if not hwnd:
raise 'Window not found'
print hwnd
win32gui.ShowWi ndow(hwnd,win32 con.SW_RESTORE)
win32gui.SetFor egroundWindow(h wnd)
time.sleep(0.1)
l,t,r,b=win32gu i.GetWindowRect (hwnd)
h=b-t
w=r-l
hwndDC = win32gui.GetWin dowDC(hwnd)
mfcDC=win32ui.C reateDCFromHand le(hwndDC)
saveDC=mfcDC.Cr eateCompatibleD C()
saveBitMap = win32ui.CreateB itmap()
saveBitMap.Crea teCompatibleBit map(mfcDC, w, h)
saveDC.SelectOb ject(saveBitMap )
saveDC.BitBlt(( 0,0),(w, h) , mfcDC, (0,0), win32con.SRCCOP Y)
temp_dir=win32a pi.GetTempPath( )
bmpname=win32ap i.GetTempFileNa me(temp_dir,'wc ')[0]+'.bmp'
saveBitMap.Save BitmapFile(save DC, bmpname)
return bmpname
Roger