向RichEdit中輸入帶格式內容

來源:互聯網
上載者:User

 

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;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.