I try to load text (formatting in RTF) to my rich text control but it doesn't work. I've even tried to use
WriteFile((HANDLE)dwCookie, myBuff, cb, (DWORD*)pcb, NULL);
instead of
*pcb = rtf->readsome((char*)pbBuff, cb);
void CreateRichEdit(HWND hwndOwner, int x, int y, int width, int height, HINSTANCE hinst)
{
LoadLibrary(TEXT("Msftedit.dll"));
edittext = CreateWindowEx(0, TEXT("RICHEDIT50W"), TEXT("Type here"), ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | ES_AUTOVSCROLL | WS_VSCROLL,
x, y, width, height,
hwndOwner, NULL, hinst, 0);
std::string teext = "{
tf1ansi{fonttbl{ f0fnilfcharset0fprq0fttruetype Helvetica; }{f1fnilfcharset0fprq0fttruetype Bitstream Charter; }}{f1fs24 Ceci est un texte accentu'e9}par{ f0fs24 avec des caract'e8res { gras},}par{ f1 des{ fs18 petits } et des{ fs32 gros }. }}";
std::stringstream rtf("{
tf1ansi{fonttbl{ f0fnilfcharset0fprq0fttruetype Helvetica; }{f1fnilfcharset0fprq0fttruetype Bitstream Charter; }}{f1fs24 Ceci est un texte accentu'e9}par{ f0fs24 avec des caract'e8res { gras},}par{ f1 des{ fs18 petits } et des{ fs32 gros }. }}");
//std::stringstream rtf("...");
EDITSTREAM es = { 0 };
es.dwError = 0;
es.dwCookie = (DWORD_PTR)&rtf;
es.pfnCallback = EditStreamInCallback;
SendMessage(edittext, EM_STREAMIN, SF_RTF, (LPARAM)&es);
}
DWORD CALLBACK EditStreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb)
{
std::stringstream * rtf = (std::stringstream*) dwCookie;
std::string text = (*rtf).str();
char myBuff[500];
*pcb = rtf->readsome((char*)pbBuff, cb);
return *pcb;
}
I've also tried to uncomment std::stringstream rtf("...");
just for writing ...
in my edit control but it doesn't work.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…