有何办法让Edit控件每一行都不同颜色?
本帖最后由 VisualEleven 于 2013-08-21 10:27:22 编辑
CString lineone = "This is Lineone";
CString linetwo = "This is Linetwo";
CString linethree = "This is Linethree";
GetDlgItem(IDC_EDIT1)->SetWindowText();
DWORD AppendText(BYTE *pdata,UINT len,COLORREF FgColor)
{
CharNewColor(FgColor);
// make a sz
BYTE *pnew=KillHalfHZ(pdata,len);
//
LONG nStartChar;
LONG nEndChar;
m_ctrlMyRichEdit.GetSel(nStartChar,nEndChar);
m_ctrlMyRichEdit.SetSel(nEndChar,nEndChar);// go end
m_ctrlMyRichEdit.ReplaceSel((LPCTSTR)pnew);
//delete [] pnew;
//
int all=m_ctrlMyRichEdit.GetLineCount();
if(all > 50) m_ctrlMyRichEdit.LineScroll(all-50,0);
//
return len;
}
BYTE *KillHalfHZ(BYTE *pdata,UINT len)
{
static BYTE HalfHZ=0;
BYTE firstHalf=0;
UINT HalfAt=0;
UINT total=0;
BYTE *copy=0;
BYTE *pTmp=0; //
if(HalfHZ !=0)
{// add last half HZ to new line
copy=new BYTE[len+1+SZ];
memset(copy,0,len+1+SZ);
copy[0]=HalfHZ;
HalfHZ=0;
memcpy(©[1],pdata,len);
total=len+1;
} else
{// keep original
copy=new BYTE[len+SZ];
memset(copy,0,len+SZ);
memcpy(copy,pdata,len);
total=len;
} pTmp=copy; // check this new line
for(UINT i=0;i<total;i++)
{
if(*pTmp >= 0x80)
{
if(firstHalf==0)
{
firstHalf = *pTmp;
HalfAt = i+1;
}
else
{// has half HZ
if(i == HalfAt)
{// 1 hz
firstHalf=0;
HalfAt=0;
}
else
{// *pTmp='?'
}
}
}
pTmp++;
} if(HalfAt == 0)
{ // new line no half HZ
copy[total]=0;
}
else if (HalfAt==total)
{// new line has half HZ at end
HalfHZ= firstHalf;
copy[total-1]=0;// sz
} // delete it after use
return copy; }