急,急,急,有关RichEditView中改变选中内容的颜色问题!
我从RichEditView类中派生出了自己的CChatClientView类,要在该类中显示文字!
我在CChatClientView类中新增了
public:
CHARFORMAT cfm;
public:
void Message(LPCTSTR lpszMessage,COLORREF clr);
在ChatClientView.cpp中新加的代码如下:
void CChatClientView::OnInitialUpdate()
{
CRichEditView::OnInitialUpdate();
// Set the printing margins (720 twips = 1/2 inch).
cfm.cbSize=sizeof(cfm);
cfm.bCharSet=GB2312_CHARSET;
cfm.crTextColor=RGB(0,255,0);
cfm.dwMask=CFM_CHARSET | CFM_COLOR ;
GetRichEditCtrl().SetDefaultCharFormat(cfm);
SetMargins(CRect(720, 720, 720, 720));
}
void CChatClientView::Message(LPCTSTR lpszMessage,COLORREF clr)
{
cfm.cbSize=sizeof(cfm);
cfm.bCharSet=GB2312_CHARSET;
cfm.crTextColor=clr;
CString strTemp = lpszMessage;
int len = GetWindowTextLength();
GetRichEditCtrl().SetSel(len,len);
GetRichEditCtrl().SetSelectionCharFormat(cfm);
GetRichEditCtrl().ReplaceSel(strTemp);
}
然后调用Message函数来显示文字,文字能显示出来,但是颜色总是不能改变,我查过MSDN,上面说的也差不多.我真的有点不明白了!请问这是为什么?
先谢了!