orORorOR
orORorOR

Reputation: 153

DrawText issues

I have a couple of issues with this function:

Am I doing it right? Maybe there's too many calls inside the WM_PAINT case? I'm not sure how else it could be done

My code:

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;
}

Upvotes: 0

Views: 269

Answers (1)

Michael Chourdakis
Michael Chourdakis

Reputation: 11178

In WM_PAINT, you must call BeginPaint() and EndPaint(). It's this way you obtain the device context. If you don't call EndPaint() the rect is not validated.

Upvotes: 4

Related Questions