🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Fixed size text

Started by
0 comments, last by PeteJ 24 years, 5 months ago
How can I print text in windows that isn''t affected by the windows font size settings? I used TextOut before, but it is affected by the font size settings.
Advertisement
Well, when you use TextOut(), it will automatically use the font associated with the current DC. If you want to change the defualt font, you have to specify a new one. Here's some code to do that.

// Select 12 Point Times New Roman Font
HFONT hOldFont = (HFONT)SelectObject(dcSurface,
CreateFont(-MulDiv(12, GetDeviceCaps(dcSurface, LOGPIXELSY), 72),
0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH / FF_ROMAN,
"Times New Roman"));

... Call TextOut()

// Restore Our Old Font
DeleteObject(SelectObject(dcSurface, hOldFont));

Personally, I hate this code. I don't know why Microsoft couldn't have had a simple function to select a font and a point size to supplement this function, but nevermind.

It's not as bad as it looks. You'll probably want to look through the docs to see what all this function does, but in reality, there are only a couple things you need to change to get this to use whatever font, size, and style that you want.

Look at this part of the first function.

(-MulDiv(12, GetDeviceCaps(dcSurface, LOGPIXELSY), 72)

This is what sets the font's point size. The first number (12) is the point size of the font. You can set this to whatever you want.

I know this probably isn't the simple answer you were hoping for, but it's really not as bad as it looks, especially if you are just wanting a specific font.

Edited by - I-Shaolin on 1/25/00 4:53:29 AM

This topic is closed to new replies.

Advertisement