獲取系統字型,獲取系統預設字型

enych發表於2024-08-21

參考 : https://www.cnblogs.com/kuangzhenxia-416/p/11728928.html

//
獲取所有字型集合 System.Drawing.Text.InstalledFontCollection MyFont = new System.Drawing.Text.InstalledFontCollection(); System.Drawing.FontFamily[] list = MyFont.Families;
 
#include <windows.h>
#include <uxtheme.h>
#include <vssym32.h>
#include <stdio.h>
 
#pragma comment(lib, "uxtheme")
 
int main()
{
    LOGFONTW lf = { 0 };
    HTHEME hTheme = OpenThemeData(0, VSCLASS_TEXTSTYLE);
    if (hTheme)
    {
        if (SUCCEEDED(GetThemeFont(hTheme, 0, TEXT_BODYTEXT, 0, TMT_FONT, &lf)))
        {
            wprintf(L"System default font name is \"%ls\"\n", lf.lfFaceName);;
} CloseThemeData(hTheme); }
return 0; }
  //// lf.lfFaceName 0x006ffcd0 L"Microsoft YaHei UI"   正確;

轉自: https://www.fournoas.com/posts/find-windows-system-default-font-name-and-font-file/

static void Main(string[] args)
{
// C#獲取系統預設字型 System.Drawing.SystemFonts.DefaultFont.Name
System.Drawing.Font font = new System.Drawing.Font(System.Drawing.SystemFonts.DefaultFont.Name, System.Drawing.SystemFonts.DefaultFont.Size);
//     顯示的是 {Name = "宋體" Size=9} ///能獲取到; 但是獲取的不正確
}

相關文章