Here the Painting the Window mentioned that:
After you finish painting the client area, you clear the update region, which tells the operating system that it does not need to send another WM_PAINT message until something changes.
One may write these code:
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
RECT rect;
GetClientRect(hWnd, &rect);
HBRUSH brush = CreateSolidBrush(RGB(127, 127, 127));
FillRect(hdc, &rect, brush);
const wchar_t * lstr = L"here is information";
TextOut(hdc,
5, 5,
lstr, _tcslen(lstr));
DrawText(hdc, TEXT("Singleline in center~"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
MoveToEx(hdc, 50, 100, NULL);
LineTo(hdc, 44, 10);
LineTo(hdc, 78, 40);
Rectangle(hdc, 16, 36, 72, 70);
Rectangle(hdc, 34, 50, 54, 70);
DeleteObject(brush);
EndPaint(hWnd, &ps);
}
What means by clear here? We do not want what we have drawn to be cleared.
WM_PAINTmessages are generated on demand (see Paint messages will come in as fast as you let them). For each window, the system maintains an update region. Clients can mark parts or all of a window's client area as "invalid", callingInvalidateRectorInvalidateRgn. Either one adds to the update area, but doesn't immediately trigger aWM_PAINTmessage.When the system determines that it's time to send a
WM_PAINTmessage, it is the client's responsibility to empty the update region when it's done painting so that no additionalWM_PAINTmessages are generated until the update region is non-empty again.The call to
BeginPaintdoes that for you, so you don't have to worry about this so long as you use standardWM_PAINThandling. If you do have more specific requirements (e.g. when using a Direct2D render target) you would have to manually clear the update region with a call toValidateRectorValidateRgn.