I need to display symbolic font on CButton of mfc. How to achieve this? A code sample is more helpful.The symbolic fonts can be from webdings or cusotm installed font.
I tried the below mentioned code but it is not working. I put this code in onpaint method of dialog box.
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();
Simply use
CreateFontIndirect
to create the font in the desired size.Use
CWnd::SetFont
to set the font to the button.Remember to Keep the font in you parent class as Long as the button or Control exists, were you used the font.
With this method you can only show chars from this font in the Control It is not possible to mix chars from other font with this method.