I have 2 CRichEditCtrls
. One is part of a dialog template, created automatically. When I call GetSelText on it, the bytes returned are one byte per char, i.e I'll get back char *str={'a','n','d'}
. The 2nd control is created dynamically using the Create
method, and the data returned calling GetSelText is returned in 2-byte characters: char *str={'a',0,'n',0,'d',0}
.
This is making things a real pain... see this topic. One way works with one control, one way works with the other.
I can't even see how two controls (on the same dialog) can have different behavior like this. I don't see a way to tell the one created dynamically what way to work.
How can this be going on? The control created dynamically is the odd one out in our application, so that's the one that needs to be changed...
Here is the code I'm using:
ASSERT(::IsWindow(m_hWnd));
CHARRANGE cr;
cr.cpMin = cr.cpMax = 0;
::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
CString strText;
LPTSTR lpsz=strText.GetBufferSetLength((cr.cpMax - cr.cpMin + 1) * 2);
lpsz[0] = NULL;
long nLen = ::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpsz);
lpsz[nLen] = NULL;
for(long i=0;i<nLen;++i)
{
TRACE("lpsz[%d] (%d bytes) = %d {",i,sizeof(lpsz[i]),lpsz[i]);
char *pc = (char *)&lpsz[i];
for(int j=0;j<sizeof(lpsz[i]);++j)
{
TRACE(" %d(%c)",pc[j],pc[j] ? pc[j] : '#');
}
TRACE("}\n");
}
strText.ReleaseBuffer();
return CString(strText);
The output from my dialog-template control:
lpsz[0] (2 bytes) = 28257 { 97(a) 110(n)}
lpsz[1] (2 bytes) = 100 { 100(d) 0(#)}
lpsz[2] (2 bytes) = 52685 { -51(Í) -51(Í)}
And from my dynamically created control:
lpsz[0] (2 bytes) = 97 { 97(a) 0(#)}
lpsz[1] (2 bytes) = 110 { 110(n) 0(#)}
lpsz[2] (2 bytes) = 100 { 100(d) 0(#)}