Windows multi-color text output help

Let's start of with the fact that I'm an MSEE, and not a CS grad. I took enough C++ to be dangerous with Unix console programs. I have a pretty strong grasp of Java and LUA (WoW AddOns), so I get the basics. The problem is with taking the Java "training wheels" off to write useful Windows programs. Java does so much for you that I'm afraid I'm going to end up reinventing the wheel or doing things the hardest way possible in Windows.

I want to make a simple program that writes MULTI-COLORED "Hello World" in a generic gray window, but I'd like to do it in a way that I can extend that process to outputting multiple lines of text or generically outputting variable values. I want to do it the "right" way. I found that TextOut let me write "Hello World" quite easily in all black text, but I want a red H, blue e, yellow l, black l, green o, etc.

Is there an "easy" way to do this, or do I have to output the red H, calculate the size and location of the H, figure out which pixel to start drawing the blue e from, change the color to blue, output the e, figure out where to draw the next letter, etc.?

Can someone please throw together a quick example of how to do what I'm looking for, or give me the bad news that it's not so simple? Thank you.
Last edited on

Is there an "easy" way to do this, or do I have to output the red H, calculate the size and location of the H, figure out which pixel to start drawing the blue e from, change the color to blue, output the e, figure out where to draw the next letter, etc.?


That's the only way I'd know how to do it. If I wanted to do something like that (I don't) I'd use a fixed pitch font to make it a bit easier, that is, all the letters would be the same width. Then you could write wrappers around a lot of the stuff where you could just have a single function with possibly three parameters, i.e., the letter, the x pixel coordinate drawing should start from, and the color (COLORREF).
closed account (E0p9LyTq)
Is there an easy way to do multi-color text output? Depends on your definition of easy:

Text Rendering with Direct2D and DirectWrite (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/ff729481(v=vs.85).aspx
That's the only way I'd know how to do it. If I wanted to do something like that (I don't) I'd use a fixed pitch font to make it a bit easier, that is, all the letters would be the same width. Then you could write wrappers around a lot of the stuff where you could just have a single function with possibly three parameters, i.e., the letter, the x pixel coordinate drawing should start from, and the color (COLORREF).
I cheated kind of like this. I switched to a mono-space font, split my string by color, padding with whitespace, then used the painter's algorithm to just overwrite the space with multiple TEXTOUT commands.

1
2
3
4
5
Red:    "H     W"
Blue:   " e     o"
Yellow: "  l     r"
Black:  "   l     l"
Green:  "    o     d"
Topic archived. No new replies allowed.