I\'m creating window using pure Win32 API (RegisterClass and CreateWindow functions). How can I specify a font for the window instead of system defined one?
In case you superclass a standard common control that already has its own font handle, use this approach: Just create a font using CreateFont
or CreateFontIndirect
and set it using WM_SETFONT
message (in MFC and ATL there would be a corresponding SetFont
function). When the font is no longer needed, destroy the font using DeleteObject
. Be sure to not destroy the window's previously set font.
In case you're writing a custom control that draws itself, just create a new font object using CreateFont
or CreateFontIndirect
and store it in your class somewhere. If you want to support third-party users, handle WM_SETFONT
and WM_GETFONT
to let the user set another font. When painting, use the current font object stored in your class.