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