Copying from the comment, I didn't put it as answer as I can't test it and I was not sure if it was correct, please test it.
In general it is not a good idea to have nested calls ie
HDC hDC1 = GetDC();
HDC hDC2 = CreateCompatibleDC(hDC1);
..
instead of
HDC hDC = CreateCompatibleDC(GetDC());
(BTW in your code the HDC returned by GetDC is not released.)
lf.lfEscapement = 90;
That should be 900 to get the text vertical, units are 0.1 degrees.
Your plan to let DrawText take care of the line breaks is going to fall flat I'm afraid. I could not convince it to align the text properly. It aligns on the last line, not the first. Some code to play with:
wchar_t* msg = L"Hello\r\nworld";
RECT rcMeasure = {0, 0, 400, 0};
DrawTextEx(hdc, msg, -1, &rcMeasure, DT_CALCRECT, 0);
RECT rcDraw = {10, 30, 10 + rcMeasure.bottom - rcMeasure.top, 30 + rcMeasure.right - rcMeasure.left };
FillRect(hdc, &rcDraw, (HBRUSH) (COLOR_WINDOW+2));
SetTextAlign(hdc, TA_TOP | TA_CENTER);
DrawTextEx(hdc, msg, -1, &rcDraw, DT_BOTTOM, 0);
I think I tried all alignment options.
Best Answer
If you want to draw text without a background fill,
SetBkMode(hdc,TRANSPARENT)
will tell GDI to leave the background when drawing text.To actually render the foreground color of the text with alpha... is going to be more complicated. GDI does not actually support alpha channels all that widely in its APIs. Outside of AlphaBlend actually all it does is preserve the channel. Its actually not valid to set the upper bits of a COLOREF to alpha values as the high byte is actually used for flags to indicate whether the COLOREF is (rather than an RGB value) a palette entry.
So, unfortunately, your only real way forward is to:
* It might be sufficient to simply memset the DIBSection with a 50% alpha before doing the DrawText, and ensure that the BKColor is black. I don't know what DrawText might do to the alpha channel though. Some experimentation is called for.