Button1_click
{
CHARFORMAT cf;
memset(&cf,0,sizeof(cf));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_UNDERLINE;
cf.dwEffects = CFE_UNDERLINE;
cf.crTextColor =  RGB(0, 0, 0);
  m_ctrlLog.SetSelectionCharFormat(cf);
  m_ctrlLog.SetSel(-1,   -1);   
  m_ctrlLog.ReplaceSel( "This is black text." );  
}
Button2_click
{
CHARFORMAT cf;
memset(&cf,0,sizeof(cf));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR;
cf.dwEffects = 0;
cf.crTextColor = RGB(255, 0, 0);
  m_ctrlLog.SetSelectionCharFormat(cf);
  m_ctrlLog.SetSel(-1,   -1);   
  m_ctrlLog.ReplaceSel("This is red text.");
}
先Button1_click 后Button2_click 上面代码可以吧颜色变掉 但是不能把下划线去掉,请教高手
另外 如果一个CEdit中也能实现 一段文本中多种颜色 和下划线功能希望 也能告诉我  谢谢

解决方案 »

  1.   

    CHARFORMAT cf;
    cf.cbSize = sizeof(CHARFORMAT);
    cf.dwMask = CFM_UNDERLINE;

    DWORD dwSelMask = GetSelectionCharFormat(cf);
    // If selection is all the same toggle UNDERLINE style
    // turn it on otherwise over the whole selection
    if( (cf.dwMask & CFM_UNDERLINE) & (dwSelMask & CFM_UNDERLINE) )  //注意这个判断

                cf.dwEffects ^= CFE_UNDERLINE; 
    }
    else

                cf.dwEffects |= CFE_UNDERLINE;
    }
    cf.dwMask = CFM_UNDERLINE;
    SetSelectionCharFormat(cf);
      

  2.   

    请问cf.dwEffects ^= CFE_UNDERLINE;   cf.dwEffects |= CFE_UNDERLINE;中的  ^=   |= 运算符号是什么意思啊
    真不好意思  谢谢