1

在我的 WTL 应用程序中,我试图更改静态标签的字体。但是 CreatePointFont 返回 NULL。为什么会这样?

CFont font;

font.CreatePointFont(120, _T("Segoe UI")); 
text.Attach(GetDlgItem(IDC_MAINTEXT));
text.SetFont(font);
4

3 回答 3

2

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.

于 2012-05-01T16:54:45.510 回答
1

该文档在失败条件上并不太冗长,但我猜你机器上没有命名字体

检查它是否由函数列出(从文档EnumFontFamilies中引用):

Windows EnumFontFamilies 函数可用于枚举所有当前可用的字体

于 2012-05-01T16:03:02.623 回答
1

的 nPointSize 参数CreatePointFont()是十分之一点,也许你的 12/10 = 1.2 点的大小太小了。你可能是想通过120

稍微轻松一点,如果您将其用于商业应用程序,您可能还想访问ban Comic sans网站。

于 2012-05-01T16:00:48.190 回答