Jump to content
  • Advertisement
Sign in to follow this  

How to change fonts on (createwindow)buttons, static, edit objects?

This topic is 5037 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, you know when you create objects using CreateWindow, eg edit, button, static objects, it has big ugly font, so I want to be able to change that, but I do not know how. Does anyone know how to change that font? Thanks

Share this post

Link to post
Share on other sites
I am assuming you are using Win32 API (no MFC)...

Step 1: In the initialization section of your program, you need to create and initialize a HFONT object - this is a handle to the font that you will use later on. You do this with the CreateFont API call (see the Platform SDK documentation for more info).

Step 2: For each window that you want to use the font on, you need to send the message WM_SETFONT. The WPARAM of the message specifies the font

Step 3: At the end of your program (program shutdown section), make sure you delete the font (just to be on the safe side). Don't delete the font until you have finished with it - otherwise, this won't work...


// Example code (each step goes in different parts of your program as described above):

// Step 1:
HFONT hFont = CreateFont(12, 0, 0, 0, 0, false, false, false, DEFAULT_CHARSET,
if ( !hFont )
// CreateFont Has Failed - Make sure you handle this!

// Step 2 (where hControl is the HWND of the target window):
SendMessage( hControl, WM_SETFONT, (WPARAM)hFont, 0);

// Step 3

Hope that helps...

James Bird

Share this post

Link to post
Share on other sites
Oops - almost forgot. If you only want to use the font that windows would normally use for buttons, static text, etc, then you don't need to call CreateFont. Instead, you could call something like:

HFONT hFont = (HFONT)GetStockObject( DEFAULT_GUI_FONT );

If you do use GetStockObject instead, then you do not need to delete the font at the end of your program, therefore you do not need to store the HFONT returned by GetStockObject. This might make life a little easier...

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!