c++ DrawText() font color and background color

CodeBlocks picture CodeBlocks · Aug 24, 2014 · Viewed 8k times · Source

How do I change the text color and font background color that is displayed when I use the DrawText() function?

Whenever I use the DrawText() function, I always output a present font as well as a "white" background color. I understand to change the font I must create the HFONT and use SelectObject to set the font, however... I did not find any color options in the CreateFont parameters (searched in msdn): http://msdn.microsoft.com/en-us/library/windows/desktop/dd183499(v=vs.85).aspx

Now, on msdn page for the DrawText() function (http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx) I found the following comment:

"The DrawText function uses the device context's selected font, text color, and background color to draw the text. "

And that is all I could find relative to text color and background color. From that sentence, I am unsure if I should be using some other GDI functions to select other objects that specify text color or background color (if those objects exist), nor am I sure if I missed something in the parameters for CreatFont().

QUESTION: How do I change the text color and font background color that is displayed when I use the DrawText() function?

Answer