强制刷新窗口并能立即生效的办法

        因为控件自绘工程skinui的缺陷,在窗口Move的时候会出现残影残留的现象,为了解决残留的问题,需要移动后马上让窗口立马刷新一下。这时,需要直接去刷新窗口并立即生效。经研究,可以使用下面的办法,如下所示:

HWND hWnd = GetSafeHwnd(); 
::Invalidate( hWnd ); 
::UpdateWindow( hWnd );

        结合msdn,让我们来分析一下上面的代码是如何使窗口立即刷新并生效的。

        msdn对Invalidate()解释如下:

Invalidates the entire client area of CWnd. 
The client area is marked for painting when the next WM_PAINT message occurs.
Windows sends a WM_PAINT message whenever the CWnd update region is not empty and there are no other messages in the application queue for that window.

       msdn对UpdateWindow()的解释则如下:

Updates the client area by sending a WM_PAINT message if the update region is not empty. 
The UpdateWindow member function sends a WM_PAINT message directly, bypassing the application queue. If the update region is empty, WM_PAINT is not sent.


       所以综上所述,调用Invalidate()使窗口无效,但必须得到系统发送WM_PAINT消息给应用程序,应用程序进行响应时才能执行刷新窗口的操作。而此时在后面如果立即调用UpdateWindow(),UpdateWindow()会绕过消息队列,直接给应用程序指定的窗口发消息,让窗口立即进行响应,从而是刷新操作立即生效。


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dvlinker

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值