UpdateWindow和Invalidate的区别

来源:互联网 发布:剑灵剑士捏脸数据大全 编辑:程序博客网 时间:2024/05/16 12:12

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消息。