UNICODE编译环境:
RTF字符串的显示:
如果是CRichEditView,可以直接用SetWindowText,输入的RTF字符串是UNCODE编码。
如果是CRichEditCtrl,可以发消息显示,输入的字符串是UNCODE编码
int CNoteView::SetRTF(TCHAR* pRtf)
{
int len = _tcslen(pRtf);
//::SendMessage(m_hWndREdit, EM_SETSEL, -1, -1); //xgz在末尾添加
::SendMessage(m_wndNote.m_hWnd, EM_SETSEL, 0, -1); //xgz替换全部
::SendMessage(m_wndNote.m_hWnd, EM_REPLACESEL, 0, (LPARAM)pRtf);
return len;
}
RTF字符串的读取:
用回调函数读取RTF, 即便是UNICODE环境,读出的RTF仍然是 CP_ACP,属性虽有SF_UNICODE,但这个只能和SF_TEXT一起用。
若是要把这个读出的RTF串,写回RichEdit显示,仍然要先转换成UNCODE编码。
int CNoteView::GetRTF(string &sRtf)
{
EDITSTREAM es = { (DWORD_PTR)&sRtf, 0, EditStreamOutCallback };
int iAttrib = SF_RTF;
//int iAttrib = SF_UNICODE; //这个只能处理文本SF_TEXT,SF_RTF即使UNICODE环境,仍然是CP_ACP, ANSI
::SendMessage(m_wndNote.m_hWnd, EM_STREAMOUT, (WPARAM)iAttrib, (LPARAM)&es);
return sRtf.length();
}
DWORD CALLBACK CNoteView::EditStreamOutCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb) //ok
{
string* psEntry = (string*)dwCookie; //指向DWORD的指针, dwCookie 实际上是 &lpRTF
//*psEntry += (char*)pbBuff; //+= 和Append 应该都是内存拼接
(*psEntry).append((char*)pbBuff); // += 和Append 应该都是内存拼接
*pcb = strlen((char*)pbBuff); //当前处理的数量
return 0;
}
标签:控件,RTF,int,SendMessage,UNICODE,字符串,SF From: https://www.cnblogs.com/xgz21/p/18440617