RedrawWindow跟InvalidateRect有什么区别
RedrawWindow和InvalidateRect有什么区别?
今天看到一段动画的程序,仿照的写了一个,
想不通RedrawWindow和InvalidateRect有什么区别,只知道不能替代,麻烦大神们解答下他俩到底有啥区别呢。
------解决方案--------------------
InvalidateRect是通过消息来调用OnPaint
RedrawWindow除了有InvalidateRect的效果,还会立即调用一次OnPaint(不经过消息队列,类似 UpdateWindow)
而这里用了循环,如果用消息(InvalidateRect)来重绘,只能等for结束后,才能响应消息进行绘图
那就不能体现动画效果了
------解决方案--------------------
简单总结就是:
Invalidate系列走消息队列
RedrawWindow不走队列,直接生效
------解决方案--------------------
Invalidate() -- RedrawWindow() -- UpdateWindow()三个函数有什么异同?
Invalidate()是强制系统进行重画,但是不一定就马上进行重画。因为Invalidate()只是通知系统,此 时的窗口已经变为无效。强制系统调用WM_PAINT,而这个消息只是Post(寄送)就是将该消息放入消息队列。当执行到WM_PAINT消息时才会对敞口进行重绘。
UpdateWindow只向窗体发送WM_PAINT消息,在发送之前判断GetUpdateRect(hWnd,NULL,TRUE)看有无可绘制的客户区域,如果没有,则不发送WM_PAINT。发送即不经过消息队列,直接发送到对应窗口,因此此函数可以立即更新窗口。
RedrawWindow()则是具有Invalidate()和UpdateWindow()的双特性。声明窗口的状态为无效,并立即更新窗口,立即调用WM_PAINT消息处理。
------解决方案--------------------
Invalidate:
Invalidates the entire client area of CWnd. The client area is marked for painting when the next WM_PAINT message occurs. The region can also be validated before a WM_PAINT message occurs by the ValidateRect or ValidateRgn member function.
==============
RedrawWindow
Updates the specified rectangle or region in the given window’s client area.
When the RedrawWindow member function is used to invalidate part of the desktop window, that window does not receive a WM_PAINT message. To repaint the desktop, an application should use CWnd::ValidateRgn, CWnd::InvalidateRgn, CWnd::UpdateWindow, or::RedrawWindow
今天看到一段动画的程序,仿照的写了一个,
- C/C++ code
void CLspiView::Animation(double x1, double y1, int x2, int y2, Ccardnode *node) { double dx=(x2-x1)/29; double dy=(y2-y1)/29; CClientDC cdc(this); CDC dc; dc.CreateCompatibleDC(&cdc); if(node->state==2) { dc.SelectObject(m_Cardback); } else { dc.SelectObject(m_CardBmp[node->num]); } int i=0; for(i=0; i<30; i++) { CRect Rect((int)x1, (int)y1, int(x1+71), int(y1+96)); RedrawWindow(Rect);// 立即重绘上一帧的画面区域 BitBltx(&cdc, (int)x1, (int)y1, 71, 96, &dc, 0, 0); x1+=dx; y1+=dy; Sleep(1); CRect rect2(int(x1-dx), int(y1-dy), int(x1-dx+71), int(y1-dy+96)); InvalidateRect(rect2, FALSE); } }
想不通RedrawWindow和InvalidateRect有什么区别,只知道不能替代,麻烦大神们解答下他俩到底有啥区别呢。
------解决方案--------------------
InvalidateRect是通过消息来调用OnPaint
RedrawWindow除了有InvalidateRect的效果,还会立即调用一次OnPaint(不经过消息队列,类似 UpdateWindow)
而这里用了循环,如果用消息(InvalidateRect)来重绘,只能等for结束后,才能响应消息进行绘图
那就不能体现动画效果了
------解决方案--------------------
简单总结就是:
Invalidate系列走消息队列
RedrawWindow不走队列,直接生效
------解决方案--------------------
Invalidate() -- RedrawWindow() -- UpdateWindow()三个函数有什么异同?
Invalidate()是强制系统进行重画,但是不一定就马上进行重画。因为Invalidate()只是通知系统,此 时的窗口已经变为无效。强制系统调用WM_PAINT,而这个消息只是Post(寄送)就是将该消息放入消息队列。当执行到WM_PAINT消息时才会对敞口进行重绘。
UpdateWindow只向窗体发送WM_PAINT消息,在发送之前判断GetUpdateRect(hWnd,NULL,TRUE)看有无可绘制的客户区域,如果没有,则不发送WM_PAINT。发送即不经过消息队列,直接发送到对应窗口,因此此函数可以立即更新窗口。
RedrawWindow()则是具有Invalidate()和UpdateWindow()的双特性。声明窗口的状态为无效,并立即更新窗口,立即调用WM_PAINT消息处理。
------解决方案--------------------
Invalidate:
Invalidates the entire client area of CWnd. The client area is marked for painting when the next WM_PAINT message occurs. The region can also be validated before a WM_PAINT message occurs by the ValidateRect or ValidateRgn member function.
==============
RedrawWindow
Updates the specified rectangle or region in the given window’s client area.
When the RedrawWindow member function is used to invalidate part of the desktop window, that window does not receive a WM_PAINT message. To repaint the desktop, an application should use CWnd::ValidateRgn, CWnd::InvalidateRgn, CWnd::UpdateWindow, or::RedrawWindow