R – Win32 Text Drawing Puzzle

drawingflickertext;winapi

I've got a little text drawing puzzle under Win32. I'm trying to draw some instructions for users of my application at the top of the window.

Please refer to the following window (I've changed the background color on the text so you can see the boundaries)

Demonstration
(source: billy-oneal.com)

I'm currently using DrawTextEx to draw the text to my window, but the problem is that it does not fill the entire RECTangle that I give it. Not drawing that area is just fine, until the window resizes:

Demonstration after resize
(source: billy-oneal.com)

When the text is re wrapped due to the window sizing, because DrawTextEx doesn't clear it's background, these artifacts are leftover.

I tried using FillRect to fill in the area behind the text drawing call, which does eliminate the visual artifacts, but then causes the text to flicker constantly, as it is completely erased and then completely redrawn to the display.

Any ideas on how one might get the area not containing text to be drawn with the background color?

EDIT: I'd like to avoid having to double buffer the form if at app possible.

EDIT2: I solved the problem by only redrawing the text when I detect that the wrapping changes during a resize.

Best Answer

Use double buffering?

Draw everything to a bitmap and draw the bitmap to the window. Flickering is commonly a double buffering issue.