Question

In my WTL app Im trying to change the font of a static label. But CreatePointFont returns NULL. Why might this be?

CFont font;

font.CreatePointFont(120, _T("Segoe UI")); 
text.Attach(GetDlgItem(IDC_MAINTEXT));
text.SetFont(font);
Was it helpful?

Solution

Are you sure that CreatePointFont is returning NULL?

For a font to be set, it must remain in memory, whereas from your code snippet it appears that the variable font is destroyed directly after setting it.

Declare the variable somewhere that will not be deleted during the lifetime of the text object, such as the class if you are using an MFC object.

OTHER TIPS

The nPointSize argument to CreatePointFont() is in tenths of a point, perhaps your size of 12/10 = 1.2 points is too small. You probably meant to pass in 120.

On a lighter note, you may also want to visit the ban comic sans web site, if you're using this for a business application.

The documentation is not too verbose on the fail conditions, but my guess it you don't have the named font on the machine

Check if it is listed by the EnumFontFamilies function (quote form the documentation):

The Windows EnumFontFamilies function can be used to enumerate all currently available fonts

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top