huidong

首页 | 会员登录 | 关于争取 2022 寒假做出汇东网 Ver3.0.0 !
搜索文章


代码源: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;
}




返回首页


Copyright (C) 2018-2024 huidong