我需要在mfc的CButton上显示符号字体。怎么做到这一点?代码示例更有帮助。符号字体可以来自webdings或cusotm安装字体。
我尝试了下面提到的代码,但它没有用。我把这段代码放在了对话框的onpaint方法中。
CWnd *win = GetDlgItem(IDC_BUTTON1);
CDC *dc = win->GetDC();
CFont font;
VERIFY(font.CreateFont(
12, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
SYMBOL_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("SAPDings"))); // lpszFacename
// Do something with the font just created...
//CClientDC dc(this);
CFont* def_font = dc->SelectObject(&font);
dc->TextOutW(5, 5, _T("0x0027"), 5);
dc->SelectObject(def_font);
// Done with the font. Delete the font object.
font.DeleteObject();
答案 0 :(得分:0)
只需使用CreateFontIndirect
即可创建所需大小的字体。
使用CWnd::SetFont
将字体设置为按钮。
请记住将字体保留在父类中,只要按钮或控件存在,是否使用了字体。
使用此方法,您只能在控件中显示此字体中的字符。此方法无法将字符与其他字体混合使用。