Search code examples
c++winapistatusbar

DrawStatusText does not draw text on first call, only on subsequent calls


I have a program that used the DrawStatusTextW() function during the WM_PAINT message. When it is called, no text is drawn. However, on subsequent calls, like moving the window under the taskbar then pulling it back up, the text is drawn.

I have tried to use different flags with the function and also tried to place it in WM_CREATE message. No effects.

   RECT status_rect;
HDC status_dc;

SNDMSG(controls.status_bar, SB_GETRECT, 0, reinterpret_cast<LPARAM>(&status_rect));
status_dc = GetDC(controls.status_bar);
SelectObject(status_dc, status_font);
DrawStatusText(status_dc, &status_rect, L"Ready.", SBT_NOBORDERS);
ReleaseDC(controls.status_bar, status_dc);

It should draw the status text on the first call. I shouldn't have to move around the window so that it redraws itself.


Solution

  • Every HWND handles its own painting. If you draw onto the status bar while painting a parent window, the status bar's own paint handling will wipe out what you drew.

    If you want to custom paint a status bar, make the status bar be owner drawn and handle the WM_DRAWITEM message in its parent window.