Original Post
I''m having some problems with a richedit control. I''m implementing it without using the MFC (I''m writing a console which I want to be able to just plug into any project, so I can''t use MFC really). Anyway, just a couple of problems.
1) It''s getting stuck on the EditStreamCallback. The function looks like this:
//-------------------------
// Console output stream callback
//-------------------------
DWORD CALLBACK CConsole::WriteStream(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
string streamStr = *(string*)dwCookie;
if(streamStr.size() < cb)
cb = streamStr.size();
memcpy(pbBuff, (BYTE*)streamStr.data(), cb);
streamStr.erase(0, cb);
*pcb = cb;
return 0;
}
The help file states:
The control calls the callback function repeatedly, transferring a portion of the data with each call. The control continues to call the callback function until one of the following conditions occurs: -The callback function returns a nonzero value. -The callback function returns zero in the *pcb parameter. -The value returned in the *pcb parameter is less than the number of bytes requested in the cb parameter. -An error occurs that prevents the rich edit control from transferring data into or out of itself. Examples are out-of-memory situations, failure of a system function, or the read buffer contains an invalid character. -For a stream-in operation, the RTF code contains data specifying the end of an RTF block. -For a stream-in operation on a single-line edit control, the callback reads in a CRLF.I''ve ran through in debug, and the cb parameter is 4096 and the *pcb ends up being about 254. According to the 3rd case, it should stop calling the callback function, but it doesn''t. If I force a nonzero return value, it stops calling it, but seeing as how 254 < 4096, it should stop calling it anyway. 2) I''m having a problem inserting text into the box. I have:
m_DocHeader = "{\\rtf1\\ansi\\deff0\\deftab720{\\fonttbl{\\f0\\froman "
"Times New Roman;}}\n{\\colortbl\\red0\\green0\\blue0;}\n"
"\\deflang1033\\pard\\tx360\\tx720\\tx1080\\tx1440\\tx1800"
"\\tx2160\\tx2520\\tx2880\\tx3240\\tx3600\\tx3960\\tx4320"
"\\tx4680\\tx5040\\tx5400\\tx5760\\tx6120"
"\\tx6480\\plain\\f3\\fs20 ";
m_DocFooter = "\n}";
I can add text into the box by adding m_DocHeader + Text + n_DocFooter, but this seems to be a waste, because i''m adding m_DocHeader every time. I know I could do it if I have the header, then my text, then the footer, but I can''t find any way of placing the selection a certain amount before the end (i.e. just before the footer), and I''m not sure if it counts the formatting parts as characters either. Any advice on how I can insert text into the control? Thanx.
---------------------------------------
Let''s struggle for our dream of Game!
http://andrewporritt.4t.com