Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am drawing a text string with a transparent background using CDC::SetBkMode(TRANSPARENT) and CDC::DrawText().

This works fine but if the text changes, I (obviously) end up with a mess on the screen as each time I draw the string, it is on top of the previous one.

What is the preferred method to erase the background before drawing the string?

What I have tried:

I have tried calling InvalidateRect() and UpdateWindow() to erase the background. I have also tried capturing the background to a bitmap and re-drawing it before drawing the text on top.

Both methods work but I would like to know if there is a better way.
Posted
Updated 18-Sep-19 15:50pm

1 solution

InvalidateRect is the appropriate method. You probably have to pass it true to cause the background to be redrawn since the text is transparent.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900