"Rune Strand" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > 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.grab() 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.FindWindow(None, window_title) if not hwnd: raise 'Window not found' print hwnd win32gui.ShowWindow(hwnd,win32con.SW_RESTORE) win32gui.SetForegroundWindow(hwnd) time.sleep(0.1) l,t,r,b=win32gui.GetWindowRect(hwnd) h=b-t w=r-l hwndDC = win32gui.GetWindowDC(hwnd) mfcDC=win32ui.CreateDCFromHandle(hwndDC) saveDC=mfcDC.CreateCompatibleDC() saveBitMap = win32ui.CreateBitmap() saveBitMap.CreateCompatibleBitmap(mfcDC, w, h) saveDC.SelectObject(saveBitMap) saveDC.BitBlt((0,0),(w, h) , mfcDC, (0,0), win32con.SRCCOPY) temp_dir=win32api.GetTempPath() bmpname=win32api.GetTempFileName(temp_dir,'wc')[0]+'.bmp' saveBitMap.SaveBitmapFile(saveDC, bmpname) return bmpname Roger -- http://mail.python.org/mailman/listinfo/python-list