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;

}

posted @ 2008-09-26 08:35  zhaogaojian  阅读(208)  评论(0编辑  收藏  举报