关于CreateFont API默认字体高度及字体匹配行为的技术咨询
CreateFont Questions Let's break down each of your questions clearly, based on Windows API behavior:
1. Default font height for CreateFont and how it selects font appearance
- Default height when using
height=0: There’s no universal hardcoded value here. Instead, the font mapper uses the default character height of the system’s default font, adjusted for the current display DPI and system locale. On most English-language Windows systems at 96 DPI (100% scaling), this typically translates to a logical height of 14—but this can vary across locales or custom system settings. - Font appearance selection logic: The mapper follows a priority chain:
- First, it tries to match the exact font name you specify (in your code,
"FixedSys"). - If that font isn’t available (or doesn’t support the required character set), it uses your other parameters:
FIXED_PITCHtells it to prioritize fixed-width fonts, whileFF_DONTCAREmeans it doesn’t restrict the font family (serif, sans-serif, etc.). It then picks the closest available fixed-width font that meets the remaining criteria.
- First, it tries to match the exact font name you specify (in your code,
2. Behavior when height=0 and what the "default height" actually is
When you pass height=0 to CreateFont, the font mapper doesn’t use a static predefined number. Instead, it calculates the height based on three key factors:
- The default font of the device context (DC) you’ll use the font with.
- The current display DPI scaling factor (e.g., 100% = 96 DPI, 125% = 120 DPI).
- Locale-specific default font settings (different regions often have optimized default fonts for their script).
In practice, this value is derived from the system’s standard UI font height, converted to logical units. For English Windows 10/11 at 100% scaling, this usually equals 14 logical units—but your Korean customer’s system likely uses a different default fixed-width font (or the same FixedSys has a different default height for Korean characters), which is why height=0 doesn’t match height=14 there.
3. Why text display differs between Korean and UK systems
This is entirely due to locale-specific font defaults:
- On UK (English) systems, the default fixed-width font (either
FixedSysitself or its closest fallback) has a default height that exactly matches your hardcoded14value at 100% scaling. Soheight=0andheight=14end up selecting the same font size, hence identical display. - On Korean systems, the default fixed-width font (optimized for Hangul characters) has a different default height at 100% scaling. When you hardcode
height=14, you’re forcing a size that doesn’t align with what the font mapper would auto-select withheight=0, resulting in visibly smaller text.
For robust DPI adaptation, avoid hardcoding values like 14. Instead, calculate the height dynamically: retrieve the current DPI of your window’s DC, scale a base logical height (e.g., 14) by the DPI ratio, and pass that scaled value to CreateFont. This ensures consistent sizing across all locales and scaling levels.
内容的提问来源于stack exchange,提问作者craker




