Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Screen capturing on Windows

8 views
Skip to first unread message

Rune Strand

unread,
Jun 13, 2006, 5:49:09 AM6/13/06
to

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.

jUr...@arcor.de

unread,
Jun 13, 2006, 8:47:48 PM6/13/06
to

Rune Strand schrieb:


As it says: the window is hidden. You can not make a screen shot of a
hidden
window 'cos it has no visual representation at the very moment. Simply
show it.
And if you do not want to see it while it's shown show it somewhere out
of the bounds of your virtual screen.

regards

Juergen

Roger Upole

unread,
Jun 14, 2006, 9:26:07 PM6/14/06
to
"Rune Strand" <rune....@gmail.com> wrote in message news:1150192149.7...@y43g2000cwc.googlegroups.com...

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


0 new messages