简体   繁体   中英

How do I get the default font(TTF) Windows Explorer is using?

Countries that use non-English characters use fonts that support their language. Chinese Windows users use Chinese fonts, and Korean users use Hangul fonts.

What I want to do is display an arbitrary directory, but I don't know what string will go into that directory. It may be in English, or it may be a path including Chinese or Japanese.

In the program I'm writing, I need to read the ttf file that matches this path and print the text.

I think the problem can be solved if I can know the fonts in use and the languages ​​supported by the fonts in Windows Explorer installed on users' PCs.

Expressed in code, it would look like this.

FontInfo f = System.Control.Desktop.captionFont;

const char *ttfPath = f.ttfPath;
// ttfPath => C:\windows\Font\myFont.ttf

const char *language = f.design;
// ttfPath => "Korean" or "Thai"

I write down how I found it. If you have a better way, please share.

  1. Retrieves the system font family name.

    Button btncsharp = new Button(); btncsharp.Content = "SystemFonts"; btncsharp.Background = SystemColors.ControlDarkDarkBrush; btncsharp.FontSize = SystemFonts.IconFontSize; btncsharp.FontWeight = SystemFonts.MessageFontWeight; btncsharp.FontFamily = SystemFonts.CaptionFontFamily; cv1.Children.Add(btncsharp);

  2. Retrieve ttf file name by font family name registry : \\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM