Question

Hi I want to clear out the DrawText() and I don't know how to do it properly. I could simply SetTextColor to the color of my background but this is not elegant way to do it I think. I dont know maybe I could do something with a rectangle rc that holds my text. I draw by case WM_PAINT and in it:

hdc=BeginPaint(hwnd, &paint);
.... //some other code here
DrawText(hdc, TEXT("some text"), -1, &rc, DT_SINGLELINE);
....//some other code here
EndPaint(hwnd, &paint);

and one more thing. I don't have DeleteDC(hdc); or ReleaseDC(hdc); in my WM_PAINT is that ok, or I should have them after or before EndPaint(hwnd, &paint);?

Was it helpful?

Solution

There's no way to "clear" text that you've drawn other than to draw something else over the top. If your background is a solid color then just draw a rectangle of that color (you can work out how big it needs to be by using the DT_CALCRECT flag with DrawText). If your background is an image then you need to blit the appropriate area of the image.

Note that drawing the text over the top of itself using the background color (as you suggest) may not work because of ClearType/anti-aliasing.

To answer your second question, no - the DC returned by BeginPaint is effectively deleted by the call to EndPaint and so you don't need to (and mustn't) delete it separately.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top