問題描述
當我想重繪一個窗口時,有沒有什么首選的函數(shù)可以在 InvalidateRect 和 RedrawWindow 之間調(diào)用?
When I want to redraw a window, is there any preferred function to call between InvalidateRect and RedrawWindow?
例如,這兩個調(diào)用是否相等:(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..)
我想重繪窗口的原因是因為我向它發(fā)送了一個我希望它顯示的新圖像,這意味著窗口的內(nèi)容不再有效.
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
不會立即重繪窗口.它只是為窗口的特定矩形區(qū)域安排"未來的重繪.使用 InvalidateRect
您可以根據(jù)需要安排任意數(shù)量的區(qū)域,使它們累積在一些內(nèi)部緩沖區(qū)中.當窗口無事可做時,所有累積預定區(qū)域的實際重繪將在稍后進行.(當然,如果在您發(fā)出 InvalidateRect
調(diào)用時窗口處于空閑狀態(tài),則會立即進行重繪).
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).
您還可以通過調(diào)用 UpdateWindow
強制立即重繪所有當前累積的無效區(qū)域.但是,同樣,如果您不著急,則沒有必要顯式調(diào)用 UpdateWindow
,因為一旦窗口空閑,它將自動為所有當前無效的區(qū)域執(zhí)行重繪.
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
是一個具有更廣泛和靈活的功能集的函數(shù).它可用于執(zhí)行失效調(diào)度(即與 InvalidateRect
所做的相同)或可用于強制執(zhí)行指定區(qū)域的立即重繪,而不進行任何調(diào)度".在后一種情況下,調(diào)用 RedrawWindow
實際上等同于調(diào)用 InvalidateRect
然后立即調(diào)用 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 的區(qū)別的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!