【发布时间】:2015-08-19 11:23:55
【问题描述】:
我有一个标准的 MFC SDI 应用程序。在关于对话框(使用 MFC 向导创建)中,我正在尝试更改一些静态文本格式(标签)。这是我的代码:
BOOL CAboutDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
auto font_programname = std::make_shared<CFont>();
font_programname->CreateFontW(25, 0, 0, 0, FW_BLACK, 0, 1, 0, 0, 0, 0, 0, 0, _T("Arial"));
_label_programname.SetFont(font_programname.get());
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
但是,这只会导致字体变粗,但大小不会改变。我做错了什么?
【问题讨论】:
-
您确定 25 是有效值吗? CreateFontW 是否返回 0?
-
另一件事:根据 MS 文档,您不应该在标签被销毁之前传递可能被销毁的 Font 对象(此处链接:support.microsoft.com/en-us/kb/85518)。您应该让 font_programname 成为 CAboutDlg 中的类成员。
-
@o_weisman 它返回 1
-
那么,我的第二个建议怎么样?
-
@o_weisman 尝试使用原始指针进行调试,输出相同!还是谢谢你!