Python win32:FillSolidRect仅在调用> = 20次时有效

时间:2011-04-01 21:44:27

标签: python windows winapi

我正在尝试使用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)

1 个答案:

答案 0 :(得分:1)

Windows对某些GDI操作进行排队/批处理以提高性能。有关如何覆盖此内容的详细信息,请参阅GdiFlush