//画线 CPen penBlack; penBlack.CreatePen(PS_SOLID, 10, RGB(255, 0, 0)); CPen* pOldPen = pDC->SelectObject(&penBlack); static int a, b; srand((unsigned)time(NULL)); a = rand() % 200; b = rand() % 200; pDC->MoveTo(a,b); pDC->LineTo(40, 40); static int c = 1;//这里的图不会被擦出, if (c == 1){ pDC->MoveTo(300, 300); pDC->LineTo(340, 340); c++; } pDC->SelectObject(pOldPen); RECT rect; rect.left = 0; rect.top = 0; rect.right = 200; rect.bottom = 200; InvalidateRect(&rect, true);//使rect区域无效并擦出rect区域原来的图 //InvalidateRect(&rect, true);//使rect区域无效并擦出rect区域并引发WM_PAINT 当移动或改变窗口大小时,pDC->MoveTo(300, 300);pDC->LineTo(340, 340);这里画的线会被擦出。说明移动或改变窗口大小是使整个窗口无效并重绘。
原文地址:http://blog.csdn.net/h1023417614/article/details/43269775