Jump to content
  • Advertisement
Sign in to follow this  
Codorke

Listing all fonts for a ANSI charset in an array

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to make a list with all fonts installed on my computer in ANSI charset into an array. I already found the function EnumFontFamiliesEx (C++) to enumerate these fonts in the MSDN but i don't get it how to use this. Can someone help me out ?

Share this post


Link to post
Share on other sites
Advertisement
This should get you started:

#include <windows.h>
#include <string>
#include <list>
#include <iostream>

int CALLBACK font_proc(
ENUMLOGFONTEX *lpelfe, // logical-font data
NEWTEXTMETRICEX *, // physical-font data
DWORD, // type of font
LPARAM lParam // application-defined data
) {
std::list<std::string> * font_list = reinterpret_cast<std::list<std::string> *>(lParam);
font_list->push_back(std::string(reinterpret_cast<TCHAR *>(lpelfe->elfFullName)));
return font_list->size();
}

int main(int, char **) {
LOGFONT lf = {};
lf.lfCharSet = ANSI_CHARSET;
lf.lfFaceName[0] = 0;
lf.lfPitchAndFamily = 0;

HWND hWnd = GetDesktopWindow();
HDC hDC = GetWindowDC(hWnd);

std::list<std::string> font_list;

EnumFontFamiliesEx(hDC, &lf, reinterpret_cast<FONTENUMPROC>(&font_proc), reinterpret_cast<LPARAM>(&font_list), 0);

std::copy(font_list.begin(), font_list.end(), std::ostream_iterator<std::string>(std::cout, "\n"));

ReleaseDC(hWnd, hDC);

return 0;
}

Share this post


Link to post
Share on other sites

question 1 :


HWND hWnd = GetDesktopWindow();

HDC hDC = GetWindowDC(hWnd);
[/qoute]

What's the different between the GetWindowDC(hWnd) and the wglGetCurrentDC() function ?
I'm always using wglGetCurrentDC() to get my hDC handler, so i don't have to get the hWnd handler first. Is ther another difference between these two ?

question 2 :

I'm still a leek in using lists but if i'm right the font_list is the array where all the ANSI charset fonts are listed in ? (I'm going to learn more about lists because i've the feeling it could help me out in a lot of different cases)

Share this post


Link to post
Share on other sites
I just used the GetWindowDC() function because this was a console application, so you don't get a device context with it like a normal window does. You might as well continue using wglGetCurrentDC().

Well, font_list is a std::list and not an array, but, yes, that's where I stuck the names of all the fonts.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!