如何从Rich Edit Win API获取RTF格式的文本? [英] How to get text with RTF format from Rich Edit Win API?

查看:230
本文介绍了如何从Rich Edit Win API获取RTF格式的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(对不起,我疯狂的英语) 我想以RTF格式获取所有格式为Rich Edit的文本,而不是纯文本格式的变量.我尝试使用带有EM_STREAMOUT的SendMessage()直接将Rich Edit写入文件,但无法将内容保存到特定变量,例如LPWSTR.请记住,只有Win API,而不是MFC.谢谢您的帮助!

(Sorry for my crazy English) I want to get all the text in Rich Edit with RTF format, not plain text to a variable. I tried SendMessage() with EM_STREAMOUT to write directly Rich Edit to file, but I can't save the content to specific variables, for example LPWSTR. Please remember, only Win API, not MFC. Thanks for you help!

推荐答案

您可以将变量传递给EM_STREAMOUT回调,以便可以根据需要对其进行更新,例如:

You can pass your variable to the EM_STREAMOUT callback so it can be updated as needed, eg:

DWORD CALLBACK EditStreamOutCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
    std::stringstream *rtf = (std::stringstream*) dwCookie;
    rtf->write((char*)pbBuff, cb);
    *pcb = cb;
    return 0;
}

.

std::stringstream rtf;

EDITSTREAM es = {0};
es.dwCookie = (DWORD_PTR) &rtf;
es.pfnCallback = &EditStreamOutCallback; 
SendMessage(hRichEditWnd, EM_STREAMOUT, SF_RTF, (LPARAM)&es);

// use rtf.str() as needed...

更新:要将RTF数据加载到RichEdit控件中,请使用EM_STREAMIN,例如:

Update: to load RTF data into the RichEdit control, use EM_STREAMIN, eg:

DWORD CALLBACK EditStreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
    std::stringstream *rtf = (std::stringstream*) dwCookie;
    *pcb = rtf->readsome((char*)pbBuff, cb);
    return 0;
}

.

std::stringstream rtf("...");

EDITSTREAM es = {0};
es.dwCookie = (DWORD_PTR) &rtf;
es.pfnCallback = &EditStreamInCallback; 
SendMessage(hRichEditWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es);

这篇关于如何从Rich Edit Win API获取RTF格式的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆