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