字体、字体大小,粗体等属性都能改,就是颜色怎么没置都没能变化,难道不能改吗?CHARFORMAT cf;
ZeroMemory(&cf, sizeof(CHARFORMAT));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask|=CFM_BOLD;
cf.dwEffects|=CFE_BOLD;//设置粗体,取消用cf.dwEffects&=~CFE_BOLD;
cf.dwMask|=CFM_ITALIC;
cf.dwEffects|=CFE_ITALIC;//设置斜体,取消用cf.dwEffects&=~CFE_ITALIC;
cf.dwMask|=CFM_UNDERLINE;
cf.dwEffects|=CFE_UNDERLINE;//设置下划线,取消用cf.dwEffects&=~CFE_UNDERLINE;
cf.dwMask|=CFM_COLOR;
cf.crTextColor = RGB(255,0,0);//设置颜色
cf.dwMask|=CFM_SIZE;
cf.yHeight =200;//设置高度
cf.dwMask|=CFM_FACE;
strcpy(cf.szFaceName ,_T("隶书"));//设置字体
rich.SetSelectionCharFormat(cf);

解决方案 »

  1.   

    void C****RichEdit::AddText(CString &strTextIn, COLORREF &crNewColor)
    {
    int iTotalTextLength = GetWindowTextLength();
    SetSel(iTotalTextLength, iTotalTextLength);
    ReplaceSel((LPCTSTR)strTextIn);
    int iStartPos = iTotalTextLength; CHARFORMAT cf;
    cf.cbSize = sizeof(CHARFORMAT);
    cf.dwMask = CFM_COLOR | CFM_UNDERLINE | CFM_BOLD;
    cf.dwEffects = (unsigned long)~( CFE_AUTOCOLOR | CFE_UNDERLINE | CFE_BOLD);
    cf.crTextColor = crNewColor;//RGB(0, 0, 0);
    // SetSelectionCharFormat(cf); int iEndPos = GetWindowTextLength();
    SetSel(iStartPos, iEndPos);
    SetSelectionCharFormat(cf);
    HideSelection(TRUE, FALSE); LineScroll(1);
    }
      

  2.   

    http://blog.csdn.net/lixiaosan/archive/2006/04/06/652795.aspx8
      

  3.   

    cf.dwEffects &= ~CFE_AUTOCOLOR加上这句呢