Search code examples
visual-c++textboxmfcappendcedit

Strange font effect after when appending text to CEdit control


After noticing the slowness of the interface updating, I followed the advice on CEdit SetWindowText rediculously slow for appending text to a CEdit control.

Then I replaced

void CMyPropertyPage::Log(const CString& sLog)
{
    CString str;
    m_cLogEdit.GetWindowText(str);

    if (!str.IsEmpty())
        str += _T("\r\n");

    str += sLog;

    m_cLogEdit.SetWindowText(str);
    m_cLogEdit.LineScroll(m_cLogEdit.GetLineCount());
}

by

void CMyPropertyPage::Log(const CString& sLog)
{
    m_cLogEdit.SetSel(-1,-1);
    m_cLogEdit.ReplaceSel(sLog + L"\r\n");

    //m_cLogEdit.LineScroll(m_cLogEdit.GetLineCount());

    UpdateData(FALSE);
    UpdateWindow();
}

Now, when I run it, I notice a strange font blurring, as it is visible in the first two lines of the Log text box in the image.

What is the cause and how can I fix it?

enter image description here


Solution

  • I solved it :)

    void CMyPropertyPage::Log(const CString& sLog)
    {
        m_cLogEdit.SetRedraw(FALSE);
    
        m_cLogEdit.SetSel(-1,-1);
        m_cLogEdit.ReplaceSel(sLog + L"\r\n");
    
        m_cLogEdit.SetRedraw(TRUE);
    
        m_cLogEdit.LineScroll(m_cLogEdit.GetLineCount());
    
        UpdateData(FALSE);
        m_cLogEdit.UpdateWindow();
    }
    

    Seems if I disable the redraw temporarily the issue is gone!