- 论坛徽章:
- 0
|
# -*- coding: cp936 -*-
import os
import ctypes
from PIL import ImageGrab
class RECT(ctypes.Structure):
_fields_ = [('left', ctypes.c_long),
('top', ctypes.c_long),
('right', ctypes.c_long),
('bottom', ctypes.c_long)]
def __str__(self):
return str((self.left, self.top, self.right, self.bottom))
def capture(hwnd,tempdir):
"""
对窗口截图,传入窗口句柄及保存位置,生成的文件为temp.jpg
"""
rect = RECT()
ctypes.windll.user32.GetWindowRect(ieHWND,ctypes.byref(rect))
rangle = (rect.left+2,rect.top+2,rect.right-2,rect.bottom-2)
im = ImageGrab.grab(rangle)
jpgname = "temp.jpg"
Xini1 = os.path.join(tempdir,jpgname)
Xini111 = Xini1.replace("\\","/")
im.save(Xini111)
return
def test1():
ieHWND = ctypes.windll.user32.FindWindowA("IEFrame",None)#获取IE的句柄
getdir = os.getcwd()
HWND_TOP = 0
SWP_NOMOVE= 2
SWP_NOSIZE= 1
SWP_SHOWWINDOW= 64
ctypes.windll.user32.SetWindowPos(ieHWND, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW)
import time
time.sleep(5)#延迟5秒
capture(ieHWND,getdir)
return
if __name__ == "__main__":
print "以IE窗口为测试窗口请先开一个IE然后再运行"
test1()
[ 本帖最后由 我不是老手 于 2009-12-2 18:26 编辑 ] |
|