这个函数有几个问题:
我做得对吗? 也许WM_PAINT案例中有太多的调用? 我不知道还能怎么做
我的代码:
case(WM_PAINT):
{
HDC hDC = GetWindowDC(Window);
RECT lpRect;
GetClientRect(Window,
&lpRect
);
SetTextColor(hDC, RGB(0, 0, 0));
SetBkMode(hDC, TRANSPARENT);
DrawTextW(hDC,
L"Loading...",
-1,
&lpRect,
(DT_SINGLELINE | DT_TOP | DT_VCENTER | DT_NOCLIP)
);
DeleteDC(hDC);
break;
}
case(WM_ERASEBKGND):
{
HDC hDC = GetWindowDC(Window);
RECT lpRect;
GetClientRect(Window, &lpRect);
HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255));
FillRect(hDC, &lpRect, hBrush);
DeleteObject(hBrush);
break;
}
在WM_PAINT中,必须调用BeginPaint和endpaint。 通过这种方式获取设备上下文。 如果不调用EndPaint,则不会验证rect。
https://docs.microsoft.com/en-us/windows/win32/gdi/wm-paint