UpdateWindow和Invalidate的区别

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值