匯東網


获取本地字体列表

[編輯] [转简体]
|
作者:huidong | 分類:【編程】Win32
[ 9 瀏覽 0 評論 1 贊 1 踩 ]

概要

正文

代码源:https://blog.csdn.net/weixin_37999268/article/details/105762661

有删改,原为 CString 类型,现改为 wstring,并删除窗口句柄传参


完整代码

#include <Windows.h>
#include <vector>
#include <string>
using namespace std;

// 回调获取每个字体
int CALLBACK NEnumFontNameProc(LOGFONT* plf, TEXTMETRIC* /*ptm*/, INT /*nFontType*/, LPARAM lParam/**/)
{
    vector<wstring>* sysFonts = (vector<wstring>*)lParam;
    wstring strVal;
    if (sysFonts != NULL)
    {
        strVal = plf->lfFaceName;
        if (strVal[0] != L'@')
        {
            sysFonts->push_back(strVal);
        }
    }
    return true;
}

// 获取本机字体列表
vector<wstring> GetSystemFontsList()
{
    vector<wstring> vFont;
    HDC hdc = GetDC(NULL);
    EnumFontFamilies(hdc, (LPTSTR)NULL, (FONTENUMPROC)NEnumFontNameProc, (LPARAM) & (vFont));
    ReleaseDC(NULL, hdc);
    return vFont;
}

int main()
{
    vector<wstring> vFont = GetSystemFontsList();
    
    return 0;
}


[ 1] [ 1]


 評論區  0 條評論

+ 添加評論