DrawText 问题

DrawText issues

这个函数有几个问题:

我做的对吗?也许 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, you must call BeginPaint() and EndPaint()。这是您获取设备上下文的方式。如果您不调用 EndPaint() 则 rect 未被验证。