当我想重绘一个窗口时,有没有什么首选的函数可以在 InvalidateRect 和 RedrawWindow 之间调用?
When I want to redraw a window, is there any preferred function to call between InvalidateRect and RedrawWindow?
例如,这两个调用是否相等:(win 将是 HWND)RedrawWindow(win, NULL, NULL, RDW_INVALIDATE);
InvalidateRect(win, NULL, NULL);
For instance, are these two calls equal: (win would be a HWND)
RedrawWindow(win, NULL, NULL, RDW_INVALIDATE);
InvalidateRect(win, NULL, NULL);
主要问题:我应该什么时候使用其中一个?背景中是否存在任何差异?(不同的 WM_messages/focus/order/priorities..)
The main question(s): When should I use one or the other? Are there any differences that happen in the background? (different WM_messages / focus / order / priorities..)
我想重绘窗口的原因是因为我向它发送了一个我希望它显示的新图像,这意味着窗口的内容不再有效.
The reason that I want to redraw the window is because I send a new image to it that I want it to display, meaning the content of the window is no longer valid.
InvalidateRect
不会立即重绘窗口.它只是为窗口的特定矩形区域安排"未来的重绘.使用 InvalidateRect
您可以根据需要安排任意数量的区域,使它们累积在一些内部缓冲区中.当窗口无事可做时,所有累积预定区域的实际重绘将在稍后进行.(当然,如果在您发出 InvalidateRect
调用时窗口处于空闲状态,则会立即进行重绘).
InvalidateRect
does not immediately redraw the window. It simply "schedules" a future redraw for a specific rectangular area of the window. Using InvalidateRect
you may schedule as many areas as you want, making them accumulate in some internal buffer. The actual redrawing for all accumulated scheduled areas will take place later, when the window has nothing else to do. (Of course, if the window is idle at the moment when you issue the InvalidateRect
call, the redrawing will take place immediately).
您还可以通过调用 UpdateWindow
强制立即重绘所有当前累积的无效区域.但是,同样,如果您不着急,则没有必要显式调用 UpdateWindow
,因为一旦窗口空闲,它将自动为所有当前无效的区域执行重绘.
You can also force an immediate redraw for all currently accumulated invalidated areas by calling UpdateWindow
. But, again, if you are not in a hurry, explicitly calling UpdateWindow
is not necessary, since once the window is idle it will perform a redraw for all currently invalidated areas automatically.
RedrawWindow
是一个具有更广泛和灵活的功能集的函数.它可用于执行失效调度(即与 InvalidateRect
所做的相同)或可用于强制执行指定区域的立即重绘,而不进行任何调度".在后一种情况下,调用 RedrawWindow
实际上等同于调用 InvalidateRect
然后立即调用 UpdateWindow
.
RedrawWindow
, on the other hand, is a function with a much wider and flexible set of capabilities. It can be used to perform invalidation scheduling (i.e. the same thing InvalidateRect
does) or it can be used to forcefully perform immediate redrawing of the specified area, without doing any "scheduling". In the latter case calling RedrawWindow
is virtually equivalent to calling InvalidateRect
and then immediately calling UpdateWindow
.
这篇关于InvalidateRect 和 RedrawWindow 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!