我是想改变控件里某一部分字体的颜色,不是所有
下面的代码好象可以改变背景颜色,但似乎改变不了字体颜色,请人指点...
CHARFORMAT   cf;   
  cf.cbSize   =   60;   
  cf.dwMask   =   CFM_COLOR|CFM_SIZE|CFM_FACE;   
  cf.yHeight   =   200;   
  cf.crTextColor   =   RGB(128,128,128);   
  strcpy(cf.szFaceName   ,_T("SimSun"));   
  m_richedit.SetDefaultCharFormat   (cf);   
  m_richedit.SetBackgroundColor(FALSE,   RGB(255,255,128));

解决方案 »

  1.   

    记得要重载重载OnCtlColor();   
      HBRUSH   CMydilog::OnCtlColor(CDC*   pDC,   CWnd*   pWnd,   UINT   nCtlColor)     
      {   
      HBRUSH   hbr   =   CDialog::OnCtlColor(pDC,   pWnd,   nCtlColor);   
        
                
              //   TODO:   Change   any   attributes   of   the   DC   here   
              int   nID   =   pWnd->GetDlgCtrlID();   
      pDC->SetBkMode(OPAQUE);   
              if(   nID   ==   IDC_EDIT2)     
      {   
                                pDC->SetTextColor(   RGB(     0,128,0   )   );//文字   
              pDC->SetBkColor(RGB(200,255,200));背景   
      }   
        
      return   hbr;   
      }   
      

  2.   

    看看这个帖子吧
    http://topic.csdn.net/u/20080510/21/3d96fe48-06e2-4733-beb3-adfd6242eb16.html
      

  3.   

    记住: 当你需要向CRichEdit追加内容时,不能用 
    m_strRichEdit += "5678\r\n"; 
    UpdateData(TRUE); 这样的代码来实现.这种方法有问题. 你应该用下面的ReplaceSel方法来实现内容的显示内容的追加 CString m_strRichEdit2 = "1234\r\n"; 
    m_richEdit.SetSel(-1,-1); 
    m_richEdit.ReplaceSel((LPCTSTR)m_strRichEdit2);
    ----------------------------------------------------------
    基本操作过程如下: C/C++ code
    SetSel(-1,-1); //将光标放在文本最末
    SetWordCharFormat(cf); //为将要输入的内容设定字体等格式
    ReplaceSel(newString); // 把新内容添加到richedit中,将采用上句设置的格式来显示,已有内容不受影响