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:
Hi,

I have a CComboBox that currently displays all the different selectable fonts in their respsective fonts. I have used the method:
EnumFontFamiliesEx(.....) 
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;
font.CreatePointFont80,"Arial");
SetFont(&font);
CClientDC dc(this);
dc.SelectObject(&font);
AddString("Arial");


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.
Posted

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
 
Comments
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.
{
.....
dlg->AddString((LPCTSTR)pelf->elfLogFont.lfFaceName:
....
}

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 :

http://msdn.microsoft.com/en-us/library/bb983806.aspx
Jackie Lloyd 1-Nov-12 14:16pm    
thanks

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