当试图截取 vmware 机器的屏幕截图时,它的内部由于某种原因被涂黑了。
我希望看到以下内容:
在计算器和少数其他应用程序上测试时,代码似乎运行良好,可能导致此问题的原因是什么?
import win32gui
import win32ui
import win32con
def backgroundScreenshot(hwnd, width, height):
wDC = win32gui.GetWindowDC(hwnd)
dcObj=win32ui.CreateDCFromHandle(wDC)
cDC=dcObj.CreateCompatibleDC()
dataBitMap = win32ui.CreateBitmap()
dataBitMap.CreateCompatibleBitmap(dcObj, width, height)
cDC.SelectObject(dataBitMap)
cDC.BitBlt((0,0),(width, height) , dcObj, (0,0), win32con.SRCCOPY)
dataBitMap.SaveBitmapFile(cDC, 'test.bmp')
dcObj.DeleteDC()
cDC.DeleteDC()
win32gui.ReleaseDC(hwnd, wDC)
win32gui.DeleteObject(dataBitMap.GetHandle())
title="Win10_64 - VMware Workstation 16 Player (Non-commercial use only)"
hwnd = win32gui.FindWindow(None, title)
print(hwnd)
backgroundScreenshot(hwnd, 900, 780)