Currently viewing: GipsySoft » Front Page» Articles

How can I change the fonts used in buttons, listboxes etc.

Basically you need to get a handle to a font (HFONT) and then use the WM_SETFONT message to change the default font used for standard controls.

A typical usage might be something like the following example code, you might do this if you have created a control using CreateWindow because the newly created window/control will use an ugly standard font.

If you create your own font to use in controls then you must keep it around for the life of the controls and then destroy it when you are done with it.

HWND hwnd = GetDlgItem( hwndDLG, IDC_OK );

//
//	Could use CreateFontIndirect(..) API to create a new font.
//	If you did create a font then you need to keep it around
//	whilst the controls are active.
HFONT hFont = GetStockObject( DEFAULT_GUI_FONT );

//
// Tell the control to use the new font.
SendMessage( hwnd, WM_SETFONT, (WPARAM)hFont, TRUE );