CRichEditCtrl 50W font issues

261 Views Asked by At

I'm dynamically (in runtime) creating a CRichEditCtrl control and when I set the text to it, the font is different from the other controls (e.g. CStatic - see the pictures) in the dialog (I didn't use any formatting for the rich edit control). The difference is best seen with the characters from alphabets like Chinese or Japanese. I tried using SetDefaultCharFormat method but it was not having the effect I wanted. Then I found out, that I first need to set the text to the rich edit control, and only then use the formatting function.

    // 1. dynamically created rich edit ctrl
    CRichEditCtrl* dynamic_rich = new CRichEditCtrl();
    dynamic_rich->Create(WS_CHILD | WS_TABSTOP | ES_LEFT | ES_MULTILINE | WS_VSCROLL |
        WS_HSCROLL | ES_WANTRETURN | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
        CRect(10, 0, 184, 23), this, 1234);
    dynamic_rich->ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_DRAWFRAME);
    dynamic_rich->SetWindowTextW(L"アラビア語"); // calling it here results in the 3rd picture
    // which is the closest to the desired result, though it's still not the same as in CStatic

    CHARFORMAT cf = { 0 };
    dynamic_rich->GetDefaultCharFormat(cf);
    _tcscpy_s(cf.szFaceName, L"MS Shell Dlg 2");
    cf.dwMask = CFM_FACE;
    dynamic_rich->SetDefaultCharFormat(cf);

    // 2. statically created rich edit ctrl - defined in .rc file
    CRichEditCtrl* static_rich = (CRichEditCtrl*)this->GetDlgItem(IDC_RICHEDIT);
    static_rich->SetWindowTextW(L"アラビア語");
    
    // 3. statically created cstatic - for the font comparison
    CStatic* label = (CStatic*)this->GetDlgItem(IDC_STATIC);
    label->SetWindowTextW(L"アラビア語");

When I leave the default font (without calling SetDefaultCharFormat) - seems blurry

enter image description here

When I call SetDefaultCharFormat, then set the text - the same result

enter image description here

When I set the text, then call SetDefaultCharFormat - not quite the same, but close

enter image description here

The font in the rich edit control still doesn't look the same as in CStatic (seems a bit different and also bigger), but that I can live with. Calling SetDefaultCharFormat every time I change a text is a problem though because I need to be constantly changing the text in the runtime and it could potentially cause an overhead. Does anybody have a better solution? Thanks.

0

There are 0 best solutions below