1.
用CRichEditCtrl前,要把AfxInitRichEdit放到InitInstance里进行初始化。不然会出错。
2.
CRichEditCtrl* m_cRichEdit = (CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT21);
m_cRichEdit->SetWindowTextA("123456/r/n67567567567/r/ndsfsdfsdf23er32/r/n");
int lineStart, lineEnd;
CHARFORMAT cFmt;
cFmt.cbSize = sizeof(CHARFORMAT);
cFmt.crTextColor = RGB(0,0,255);
cFmt.dwEffects = 0;
cFmt.dwMask = CFM_COLOR;
lineStart = m_cRichEdit->LineIndex(0);//取第一行的第一个字符的索引
lineEnd = m_cRichEdit->LineIndex(1)-1;//取第一行的最后一个字符的索引——用第二行的第一个索引减1来实现
m_cRichEdit->SetSel(lineStart,lineEnd);//选取第一行字符
m_cRichEdit->SetSelectionCharFormat(cFmt);//设置颜色
cFmt.crTextColor = RGB(0,255, 0);
lineStart = m_cRichEdit->LineIndex(1);//取第一行的第一个字符的索引
lineEnd = m_cRichEdit->LineIndex(2)-1;//取第一行的最后一个字符的索引——用第二行的第一个索引减1来实现
m_cRichEdit->SetSel(lineStart,lineEnd);//选取第一行字符
m_cRichEdit->SetSelectionCharFormat(cFmt);//设置颜色
cFmt.crTextColor = RGB(255, 0, 0);
lineStart = m_cRichEdit->LineIndex(2);//取第一行的第一个字符的索引
lineEnd = m_cRichEdit->LineIndex(3)-1;//取第一行的最后一个字符的索引——用第二行的第一个索引减1来实现
m_cRichEdit->SetSel(lineStart,lineEnd);//选取第一行字符
m_cRichEdit->SetSelectionCharFormat(cFmt);//设置颜色
用CRichEditCtrl前,要把AfxInitRichEdit放到InitInstance里进行初始化。不然会出错。
2.
CRichEditCtrl* m_cRichEdit = (CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT21);
m_cRichEdit->SetWindowTextA("123456/r/n67567567567/r/ndsfsdfsdf23er32/r/n");
int lineStart, lineEnd;
CHARFORMAT cFmt;
cFmt.cbSize = sizeof(CHARFORMAT);
cFmt.crTextColor = RGB(0,0,255);
cFmt.dwEffects = 0;
cFmt.dwMask = CFM_COLOR;
lineStart = m_cRichEdit->LineIndex(0);//取第一行的第一个字符的索引
lineEnd = m_cRichEdit->LineIndex(1)-1;//取第一行的最后一个字符的索引——用第二行的第一个索引减1来实现
m_cRichEdit->SetSel(lineStart,lineEnd);//选取第一行字符
m_cRichEdit->SetSelectionCharFormat(cFmt);//设置颜色
cFmt.crTextColor = RGB(0,255, 0);
lineStart = m_cRichEdit->LineIndex(1);//取第一行的第一个字符的索引
lineEnd = m_cRichEdit->LineIndex(2)-1;//取第一行的最后一个字符的索引——用第二行的第一个索引减1来实现
m_cRichEdit->SetSel(lineStart,lineEnd);//选取第一行字符
m_cRichEdit->SetSelectionCharFormat(cFmt);//设置颜色
cFmt.crTextColor = RGB(255, 0, 0);
lineStart = m_cRichEdit->LineIndex(2);//取第一行的第一个字符的索引
lineEnd = m_cRichEdit->LineIndex(3)-1;//取第一行的最后一个字符的索引——用第二行的第一个索引减1来实现
m_cRichEdit->SetSel(lineStart,lineEnd);//选取第一行字符
m_cRichEdit->SetSelectionCharFormat(cFmt);//设置颜色