Click here to Skip to main content
15,850,921 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have a CComboBox that currently displays all the different selectable fonts in their respsective fonts. I have used the method:
and it works great.

However, I now need to only show a few of these font options. Is there an easy way to just select e.g. Arial, Calibri, Times New Roman to be displayed in the combobox in their own fonts?

I couldn't find a way to do this using the EnumFontFamiliesEx method so I tried to use the following code, but it did not change the font style shown in the combo box, although the string "Arial" was added (MyComboBox class is derived from CComboBox):
void MyComboBoxClass::SetFonts()
CFont font;
CClientDC dc(this);

I changed the owner draw setting of the combo box to all its options and nothing helped.

Is there a simple way to do what I am trying to do, or can someone help me figure out the complicated way please?
Very many thanks in advance for any help.

1 solution

I don't have a solution for you, but have a look at the CMFCFontCombBox control (VS2008+feature pack or later), it might not exactly work for you, but it could be a good start.

Also, I don't understand, do you manually fill a combo box and display the items yourself?

If that is the case, why can't use just still use EnumFontFamiliesEx and filter in (or out) the fonts you want to use?

Good luck.
Share this answer
Jackie Lloyd 1-Nov-12 5:19am    
Hi there, Thank you very much for your reply. I googled the CMFCFontComboBox but it didn't seem bring up any hits - do you have a link to any info. However your suggestions helped me find the answer. In the callback method in my code 'MyComboBox::EnumFontFamExProc(ENUMLOGFONTEX* pelf, ........)
I checked the name of each font in the enumeratioon before adding it to the combo box.
CString s(pelf->elfLogFont.lfFaceName);
if(!s.Compare("Arial") || !s.Cpmapre("Times New Roman") etc.

It seems obvious now, but I just didn't realise, so thank you.
Maximilien 1-Nov-12 8:47am    
Surprised google did not get a hit on CMFCFontComboBox ? it is part of MFC :
Jackie Lloyd 1-Nov-12 14:16pm    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900