Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Correct" Dialog / UI font on Windows

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?

like image 667
peterchen Avatar asked May 31 '10 10:05

peterchen


People also ask

What font does Windows GUI use?

Segoe UI (pronounced "SEE-go") is the Windows system font. The standard font size has been increased to 9 point.

Is Segoe UI a good font?

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.

What font does Windows 98 use?

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.


1 Answers

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.

like image 77
In silico Avatar answered Oct 07 '22 16:10

In silico