When creating a control (e.g. an edit control) on the fly using CreateWindow, it usually starts out with an ugly (boldish sans serif) font.
Usually I wok around that by grabbing the parent dialog's font, and setting it to the control - I can't even say if this is a good idea.
How do I "legally" fetch the right font?
Segoe UI (pronounced "SEE-go") is the Windows system font. The standard font size has been increased to 9 point.
Segoe UI is a proud, professional font that is suitable for a wide range of applications – a powerful asset to any team. There are few fonts – few of anything, even – that invite more hatred than Comic Sans.
MS Sans Serif is the default system font on Windows 3.1, Windows 95, Windows NT 4.0, Windows 98, and Windows ME. A Euro symbol was added to this font for the release of Windows 98.
The "correct" way to get the font used in dialog boxes like message boxes, etc. would be via the SystemParametersInfo()
function:
// C++ example
NONCLIENTMETRICS metrics;
metrics.cbSize = sizeof(NONCLIENTMETRICS);
::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS),
&metrics, 0);
HFONT font = ::CreateFontIndirect(&metrics.lfMessageFont);
::SendMessage(ctrlHWND, WM_SETFONT, (WPARAM)font, MAKELPARAM(TRUE, 0));
Don't forget to destroy the font when the controls are destroyed:
::DeleteObject(font);
You can look up the MSDN documentation for NONCLIENTMETRICS
and SystemParametersInfo()
to see what other system-wide parameters you can retrieve.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With