python--获得特定程序的屏幕截图并保存为文件
2021-02-17 15:18
标签:屏幕截图 pad com 保存 resources rcc eth source notepad 主要是利用win32库 python--获得特定程序的屏幕截图并保存为文件 标签:屏幕截图 pad com 保存 resources rcc eth source notepad 原文地址:https://www.cnblogs.com/strive-sun/p/12696898.htmlimport win32gui
import win32ui
import win32con
name = "test.txt - Notepad"
hwnd = win32gui.FindWindow(None, name)
left, top, right, bot = win32gui.GetWindowRect(hwnd)
w = right - left
h = bot - top
print(w,h)
wDC = win32gui.GetWindowDC(hwnd)
dcObj=win32ui.CreateDCFromHandle(wDC)
cDC=dcObj.CreateCompatibleDC()
dataBitMap = win32ui.CreateBitmap()
dataBitMap.CreateCompatibleBitmap(dcObj, w, h)
cDC.SelectObject(dataBitMap)
cDC.BitBlt((0,0),(w, h) , dcObj, (0,0), win32con.SRCCOPY)
dataBitMap.SaveBitmapFile(cDC, "1.bmp")
# Free Resources
dcObj.DeleteDC()
cDC.DeleteDC()
win32gui.ReleaseDC(hwnd, wDC)
win32gui.DeleteObject(dataBitMap.GetHandle())
文章标题:python--获得特定程序的屏幕截图并保存为文件
文章链接:http://soscw.com/index.php/essay/56622.html