小编And*_*eie的帖子

使用对 EnumFontFamiliesEx 的 DLL 调用枚举 C# 中的活动字体让我感到困惑

我的最终目标是列出 Windows 计算机上的所有活动字体。例如,如果您启动 WordPad 或 Word,您将看到它们全部。其中一些字体来自 windows\fonts 文件夹,但不是全部。有些是使用 gdi32.dll 调用 AddFontResource(...) 动态注册的。现在,您会认为 C# 支持检索整个列表,如果是这样,请告诉我!

但是,在为此花费大量时间之后,用于获取已安装系统字体的常规 C# 调用只会检索所有实际处于活动状态的字体中的一部分。例如,InstalledFontCollection.Families 没有找到任何使用 AddFontResource 添加的字体(它找到了写字板中列出的大约 25% 的字体!)

虽然我想在 C# 中执行此操作,但似乎我必须使用更多 gdi32.dll 调用。因此开始了我的 EnumFontFamiliesEx 问题。

我已经设法使以下代码工作到我收到一堆带有字体的回调的程度。但是,结构 ENUMLOGFONTEX 似乎已损坏,例如 lpelfe.elfFullName 通常包含几个方形字符,从来没有真正的名字。也许我在编组或结构定义中犯了一个错误,不太确定。我尝试了许多迭代和无休止的谷歌搜索,但无济于事。

任何帮助将不胜感激。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Media;
using System.Runtime.InteropServices;
using Microsoft.Win32;


namespace FontRetriever
{
public partial class TestForm : Form
{

    [DllImport("gdi32.dll")]
    static extern int EnumFontFamiliesEx(IntPtr hdc,
    [In] IntPtr pLogfont,
    EnumFontExDelegate lpEnumFontFamExProc,
    IntPtr lParam, …
Run Code Online (Sandbox Code Playgroud)

c# dll fonts gdi callback

3
推荐指数
1
解决办法
3279
查看次数

标签 统计

c# ×1

callback ×1

dll ×1

fonts ×1

gdi ×1