RichEditView自写WriteColorMessage
nt CIOCPClientView::WriteColorMessage(CString message, COLORREF color)
{
int nOldLines = 0, nNewLines = 0, nScroll = 0;
long nInsertionPoint = 0;
CHARFORMAT cf;
// Save number of lines before insertion of new text
nOldLines = this->GetRichEditCtrl().GetLineCount();
// Initialize character format structure
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR;
cf.dwEffects = 0; // To disable CFE_AUTOCOLOR
cf.crTextColor = color;
// Set insertion point to end of text
nInsertionPoint = this->GetRichEditCtrl().GetWindowTextLength();
this->GetRichEditCtrl().SetSel(nInsertionPoint, -1);
// Set the character format
this->GetRichEditCtrl().SetSelectionCharFormat(cf);
// Replace selection. Because we have nothing
// selected, this will simply insert
// the string at the current caret position.
this->GetRichEditCtrl().ReplaceSel(message);
// Get new line count
nNewLines = this->GetRichEditCtrl().GetLineCount();
// Scroll by the number of lines just inserted
nScroll = nNewLines - nOldLines;
this->GetRichEditCtrl().LineScroll(nScroll);
//PostMessage(WM_VSCROLL, SB_BOTTOM,0); 上面那句改成这句话能提高速度
char firstline[1024];
this->GetRichEditCtrl().GetLine(0,firstline);
if(nNewLines>6)
{
this->GetRichEditCtrl().SetSel(0,strlen(firstline ));
//WriteContentToRTF("old.rtf");
//this->SetWindowTextA("");
this->GetRichEditCtrl().ReplaceSel("",0);
}
return 0;
}
另外建了几个QQ技术群:
2、全栈技术群:616945527
2、硬件嵌入式开发: 75764412
3、Go语言交流群:9924600
闲置域名WWW.EXAI.CN (超级人工智能)出售。