因为控件自绘工程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.