I\'m trying to create a list of fonts for the user to choose from. I\'m doing this by using the EnumFontFamiliesEx function but unfortunately, the list of returned fonts is
It's disgraceful that Microsoft haven't documented this functionality, to be honest, but more and more this is what we've come to expect from them.
Another way to filter your own list of fonts is to leverage the shell by enumerating the fonts folder. If you look with Explorer you'll see that hidden fonts are displayed with a ghosted icon - we can use that attribute to tell if the font is hidden.
For example (not complete):
LPITEMIDLIST pidlFonts;
if (SUCCEEDED(SHGetKnownFolderIDList(FOLDERID_Fonts, 0, nullptr, &pidlFonts)))
{
CComPtr psf;
if (SUCCEEDED(SHBindToObject(nullptr, pidlFonts, nullptr, IID_IShellFolder, reinterpret_cast(&psf))))
{
CComPtr pEnum;
if (SUCCEEDED(psf->EnumObjects(hWnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN | SHCONTF_INIT_ON_FIRST_NEXT, &pEnum)))
{
LPITEMIDLIST pidl;
ULONG celt = 0;
while (pEnum->Next(1, &pidl, &celt) == S_OK)
{
SFGAOF hidden = SFGAO_GHOSTED;
if (SUCCEEDED(psf->GetAttributesOf(1, const_cast(&pidl), &hidden)) && (hidden & SFGAO_GHOSTED) == SFGAO_GHOSTED)
{
// this font should be hidden
// get its name via IShellFolder::GetDisplayNameOf
}
CoTaskMemFree(pidl);
}
}
}
CoTaskMemFree(pidlFonts);
}
You could use this method to build a set of hidden fonts and then use that to filter the results of EnumFontFamiliesEx.