John James
John James

Reputation: 277

GDI Erasing Residual Text with Transparent Background

I'm creating a GDI window that contains a background image, along with some static text (with transparent background) on top of the image. I want the text to display different messages at different times. To get the transparent background working, I've intercepted the WM_CTLCOLORSTATIC message in the WndProc to set the background color to transparent and return NULL_BRUSH like so

case WM_CTLCOLORSTATIC:
{
    HDC hdcStatic = (HDC)wParam;
    SetTextColor(hdcStatic, rgbWhite);
    SetBkMode(hdcStatic, TRANSPARENT);
    return (LRESULT)GetStockObject(NULL_BRUSH);
}

Currently it's working the first time the window is drawn. However, when I update the text by sending SendMessageW(hWndText.get(), WM_SETTEXT, 0, (LPARAM) newMessage);, the new message is displayed but the old text remains.

I know that this is because I'm returning GetStockObject(NULL_BRUSH) in WM_CTLCOLORSTATIC, so it's erasing the background with nothing before drawing the new text. I believe I can fix this by finding the portion of the background image that is behind this static text and using that as the background brush instead, but is there a better way to do this?

Upvotes: 0

Views: 26

Answers (0)

Related Questions