1. Replace invalidate () with InvalidateRect ()
Invalidate () will cause the entire window to redraw the image, it takes a long time, and InvalidateRect () only redraw the contents of the Rect area, so it takes less time. Bugs used to be lazy, often for a small area of the redraw call invalidate (), you don't want to compute the rect that you need to repaint, but the fact is, if you really need to improve the flicker, it takes a lot less time to compute a rect than lifting the content that doesn't need to be repaint.
2. Prohibit the system from wiping your window
The system will help you erase the window with the specified background color when you need to redraw the window. However, perhaps the area that needs to be repaint may be very small. Or, it's going to take a lot of computing to get started when you redraw these things. This time you can stop the system from wiping out the original image. Until you have calculated all the data, you cover the parts that need to be erased with the background color (e.g. DC. FillRect (Rect,&brush), Rect is the area that needs to be erased, brush is a brush with background color, and then draw new graphics. To prevent the system from wiping your window, you can overload the OnEraseBkgnd () function so that it can be returned directly to Pue. Such as
BOOL CMyWin::OnEraseBkgnd(CDC* pDC)
{
return pUE;
//return CWnd::OnEraseBkgnd(pDC);//把系统原来的这条语句注释掉。
}
3, effective for wiping apart
In addition to the background, do not rub the wrong place to rub. For example, you put a large edit box on a window, almost the entire window, then you frequently wipe the entire window background will cause edit to repeatedly redraw the form of intense flashing. In fact, you can crgn create an area that needs to be erased, and only rub this part. Such as
GetClientRect(rectClient);
rgn1.CreateRectRgnIndirect(rectClient);
rgn2.CreateRectRgnIndirect(m_rectEdit);
if(rgn1.CombineRgn(&rgn1,&rgn2,RGN_XOR) == ERROR)//处理后的rgn1只包括了Edit框之外的客户区域,这样,Edit将不会被我的背景覆盖而导致重画。
{
ASSERT(FALSE);
return ;
}
brush.CreateSolidBrush(m_clrBackgnd);
pDC->FillRgn(&rgn1,&brush);
brush.DeleteObject();
Note: Use method two at the same time when using this method. Don't forget, it's time to say that the worm is not the way.