I'm trying to draw a rectangle on my screen using the win32 python libs. For some reason it works if I call FillSolidRect 20 times in a row, but if I call it less than that it doesn't work. Can anybody give a hint as to why?
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), (s开发者_JAVA技巧creen_width, screen_height), shot_dc, (0, 0), win32con.SRCCOPY)
Windows queues/batches certain GDI operations to enhance performance. See GdiFlush for more information on how to override this.
精彩评论