UpdateWindow和Invalidate的區別
MSDN的解釋
UpdateWindow
The UpdateWindow function updates the client area of the specified window by sending a WM_PAINT message to the window if the window 's update region is not empty. The function sends a WM_PAINT message directly to the window procedure of the specified window, bypassing the application queue. If the update region is empty, no message is sent.
InvalidateRect
The system sends a WM_PAINT message to a window whenever its update region is not empty and there are no other messages in the application queue for that window.
翻譯成中文大概的解釋如下:
UpdateWindow:如果有無效區,則馬上sending a WM_PAINT message到視窗處理過程,不進訊息佇列進行排隊等待,立即重新整理視窗,否則,什麼都不做。
InvalidateRect:設定無效區,如果為NULL參數,則設定整個視窗為無效區。當應用程式的那個視窗的訊息佇列為空白時,則sending a WM_PAINT message(即使更新地區為空白).在sending a WM_PAINT message的所有InvalidateRect的更新地區會累加。
所以一般的用法是
1:設定無效區
InvalidateRect
2:立即重新整理
UpdateWindow();
如果不調用 InvalidateRect就調用 UpdateWindow,那麼UpdateWindow什麼都不做。
如果調用 InvalidateRect 後不調用UpdateWindow,則系統會自動在視窗訊息佇列為空白的時候,系統自動發送一WM_PAINT訊息。