我正在尝试使用win32 python库在屏幕上绘制一个矩形。出于某种原因,如果我连续20次调用FillSolidRect,它会起作用,但是如果我把它称为小于它,它就不起作用。任何人都可以暗示为什么?
import time
from ctypes import windll
from win32api import GetSystemMetrics
import win32ui, win32con
screen_width, screen_height = GetSystemMetrics(0), GetSystemMetrics(1)
dc = windll.user32.GetDC(0)
screen_dc = win32ui.CreateDCFromHandle( dc )
shot_dc = screen_dc.CreateCompatibleDC()
shot_bitmap = win32ui.CreateBitmap()
shot_bitmap.CreateCompatibleBitmap(screen_dc, screen_width, screen_height)
shot_dc.SelectObject(shot_bitmap)
shot_dc.BitBlt((0, 0), (screen_width, screen_height), screen_dc, (0, 0), win32con.SRCCOPY)
' Have to draw >= 20(?) times or nothing will get drawn (for some reason).'
for i in range(20): screen_dc.FillSolidRect((0,0,100,100), 0x000000),
time.sleep(1)
screen_dc.BitBlt((0, 0), (screen_width, screen_height), shot_dc, (0, 0), win32con.SRCCOPY)