Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Win32 DrawText line height

Tags:

text

winapi

gdi

I'm calling the Win32 DrawText function to output some text into a device context. The text is long and wraps nicely onto a second line. The problem is I need to decrease the space between lines a bit (I guess decrease the line height?). Any ideas on how to do this?

I would just call DrawText twice (one for each line) but then I have to do my own word wrap.

Is there any other way?

Thanks

like image 833
DougN Avatar asked Nov 18 '09 20:11

DougN


2 Answers

It's been quite a while since I dealt with this on Win32, but I believe the font itself defines the "expected" spacing by defining empty space below the character. Drawtext uses this full "height to position the next line when wrapping. If you want to do something which is not in alignment with this sizing, I believe you will have to do your own wrapping calculations and multiple DrawText() calls.

like image 97
cdkMoose Avatar answered Sep 20 '22 08:09

cdkMoose


One possibility is to put the text into a disabled Rich Edit Control. I think that gives you a lot of control over formatting.

If you do write your own word wrap, you probably want to use GetTextExtentExPoint() for measuring how much will fit in each line.

like image 34
Adrian McCarthy Avatar answered Sep 21 '22 08:09

Adrian McCarthy