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

来源:互联网 发布:现实中网络女主播好丑 编辑:程序博客网 时间:2024/06/02 22:57

        因为控件自绘工程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()会绕过消息队列,直接给应用程序指定的窗口发消息,让窗口立即进行响应,从而是刷新操作立即生效。


原创粉丝点击