Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

c++ win32, how to set DrawText font?

This topic is 4451 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, im drawing text onto the window with DrawText. I want to change the font of the text. I've tried: HFONT font = CreateFont(18, 0, 0, 0, 300, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial"); SendMessage(handle, WM_SETFONT, (WPARAM)font, TRUE); which doesn't do anything. Any ideas? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You have to use SelectObject to select the HFONT into the HDC you use with DrawText. You should also store the original HFONT and select it back in after you're done:


// drawing code

// select the font in
HFONT hFontOld = (HFONT)SelectObject( hDC, font );

DrawText( hDC, ... );

// put back the old font
SelectObject( hDC, hFontOld );

Share this post


Link to post
Share on other sites
Agreed... once critical thing to always remember about GDI elements....

just like pointers new and delete...

if you call create You must call destroy.

IE:

HFONT font = CreateFont(18, 0, 0, 0, 300, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial");

then.... when your program ends
same with HDCS.... but if you use a buffer its either DestroyDC() or ReleaseDC() i believe.

DestroyObject(font);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!