向RichEdit中输入带格式内容
static DWORD CALLBACK EditStreamCallBack(DWORD dwCookie, LPBYTE pbBuff, LONG cb,
LONG *pcb)
{
char *pstr = (char *)dwCookie;
int nLen = strlen(pstr);
if(nLen<cb)
{
CopyMemory(pbBuff,pstr,nLen);
}
else
{
*pcb = cb;
CopyMemory(pbBuff,pstr,cb);
CopyMemory(pstr,pstr+cb,nLen-cb);
}
return 0;
}
调用,输出CString到RichEdit
CString strTxt;
CString sHead = CString("{\\rtf1\\ansi\\ansicpg936\\deff0\\deflang1033\\deflangfe2052{\\fonttbl{\\f0\\fnil\\fprq2\\fcharset134 \\'cb\\'ce\\'cc\\'e5;}{\\f1\\froman\\fprq2\\fcharset0 Times New Roman;}}")
+CString("{\\colortbl ;\\red192\\green0\\blue192;\\red0\\green0\\blue0;}")
+CString("\\viewkind4\\uc1\\pard\\nowidctlpar\\fi-1134\\li1134\\sa120\\fs24");
CString sTail = CString("}");
CString strTemplate = CString("\\cf1\\lang2052\\f0 {%time%}\\cf0 \\cf2{%message%}\\cf0\\lang1033\\f1\\par");
CString strTmp;
CString strTime;
CString strMsg;
for(int i=0;i
MyMsgStruct* pObj = (MyMsgStruct*)m_MsgStruList.GetAt(i);
strTmp = strTemplate;
strTmp.Replace(_T("{%time%}"),pObj->sTime);
strTmp.Replace(_T("{%message%}"),pObj->sMsg);
if(m_nSortId == 1)
strTxt += strTmp;
else
strTxt = strTmp + strTxt;
}
strTxt = sHead + strTxt + sTail;
char* pBuf=new char[strTxt.GetLength()*2];
WCharToChar(strTxt,strTxt.GetLength(),pBuf,strTxt.GetLength()*2);
EDITSTREAM es = {(DWORD)pBuf, 0, EditStreamCallBack};
m_wndRichEdit.StreamIn(SF_RTF , es);
delete pBuf;