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

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

## 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 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:

// 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,			 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial");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 3DeleteObject(hFont)

Hope that helps...

James Bird

##### 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...

thanks alot!