My goal is to let users set specific font on selection in the RichEdit control.
So I do it as such in code:
#define SIZEOF(f) (sizeof(f)/sizeof(f[0]))
CString m_strName = L"Script";
CHARFORMAT2 cf3;
memset(&cf3, 0, sizeof(cf3));
cf3.cbSize = sizeof(cf3);
cf3.dwMask = CFM_FACE | CFM_CHARSET;
//Set type face
memcpy(cf3.szFaceName, m_strName.GetString(), min(SIZEOF(cf3.szFaceName), m_strName.GetLength() + 1) * sizeof(TCHAR));
cf3.szFaceName[SIZEOF(cf3.szFaceName) - 1] = 0;
//Both m_nCharSet and m_nPitchAndFamily are taken from EnumFontFamiliesEx() API
cf3.bCharSet = m_nCharSet;
cf3.bPitchAndFamily = m_nPitchAndFamily;
//pRichEdit is CWnd for RichEdit box of class RichEdit50W
if(pRichEdit->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION | SCF_USEUIRULES, (LPARAM)&cf3))
{
bRes = TRUE;
}
This works on my Windows 8.1 desktop, but on my test Windows 7 machine the following happens:
- If I first select "Script" font, it will render it correctly:
- But then if I close and then reopen the app and first select "WingDings", it will also render correctly:
and then if I switch font selection immediately to "Script" I get this:
Which is incorrect.
So I'm wondering what am I doing wrong there?