UpdateWindow和Invalidate

来源:互联网 发布:网络协议组成部分为() 编辑:程序博客网 时间:2024/06/04 23:27

The UpdateWindow function updates the client area of the specified window by sending aWM_PAINT message to the window if the window's update region is not empty. The function sends aWM_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. 


The InvalidateRect function adds a rectangle to the specified window's update region. The update region represents the portion of the window's client area that must be redrawn. 

The invalidated areas accumulate in the update region until the region is processed when the nextWM_PAINT message occurs or until the region is validated by using theValidateRect or ValidateRgn function.

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.

If the bErase parameter is TRUE for any part of the update region, the background is erased in the entire region, not just in the specified part. 

翻译成中文大概的解释如下: 
 UpdateWindow:如果有无效区,则马上发送  WM_PAINT  消息到窗口处理过程,不进消息队列进行排队等待,立即刷新窗口,否则,什么都不做。
 InvalidateRect:设置无效区,如果为NULL参数,则设置整个窗口为无效区。当应用程序的那个窗口的消息队列为空时,则发送 WM_PAINT  消息(即使更新区域为空).在sending   a   WM_PAINT   message的所有InvalidateRect的更新区域会累加。


所以一般的用法是 
  1:设置无效区 
  InvalidateRect 
  2:立即刷新 
  UpdateWindow(); 
如果不调用   InvalidateRect就调用   UpdateWindow,那么UpdateWindow什么都不做,因为没有无效区域。 
如果调用   InvalidateRect   后不调用UpdateWindow,则系统会自动在窗口消息队列为空的时候,系统自动发送一WM_PAINT消息,而不是立即刷新。

参考:http://blog.csdn.net/lpt19832003/article/details/4312527
原创粉丝点击