在这里画窗提到:
绘制完客户区后,清除更新区域,这会告诉操作系统它不需要发送另一个 WM_PAINT 消息,直到发生变化。
可以编写以下代码:
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);
}
这里的清除是什么意思?我们不希望我们绘制的内容被清除。