I was playing around with the different versions of Rich Edit, and noticed something that has me a bit confused.

For streaming a file into the rich edit control, I use the same proceedure for the different versions(1 or 2):
invoke SendMessage,.hREdit,EM_STREAMIN,SF_TEXT,addr ess

This works fine.

Then I checked the length of text in the edit control with this code.

LOCAL gtl:GETTEXTLENGTHEX
------
------
mov gtl.flags,GTL_DEFAULT
mov gtl.codepage,CP_ACP
INVOKE SendMessage,.hEdit,EM_GETTEXTLENGTHEX,addr gtl,0

Next I changed the flags member of the GETTEXTLENGTHEX struct. and checked the length again with this code.
 
mov gtl.flags,GTL_NUMBYTES
INVOKE SendMessage,.hEdit,EM_GETTEXTLENGTHEX,addr gtl,0


With version 1 of the rich edit control, the 2 returned values are the same.
with version 2 of the rich edit control, the 2 returned values differ, with the value returned when the flags member is set to GTL_NUMBYTES being double the first value.

Is this because version 2 and above treat the text streamed into it as UNICODE, no matter what stream format (SF_TEXT) is set at time of streaming?

Thanks,
Rags
Posted on 2006-05-23 06:43:14 by rags
rags,
Yes, it is because it thinks it is UNICODE.  I had to check your results because I only ever use SF_TEXT.  I just don't use UNICODE, don't ask me why.  Anyway, your results are certainly valid.

BTW:  Radasm has RAEdit.dll, have you played with that, yet?
Paul
Posted on 2006-05-23 07:01:40 by PBrennick
Paul,
Thanks for the verification of what I was thinking was the reason for the difference.
I have'nt had the chance to play with RAEdit yet.
Rags
Posted on 2006-05-23 07:13:22 by rags
rags,
In order to understand why you would do that, are you getting the length of the text to be used in a search?  If so and if you are searching text then why the HEX flag, it will always yield erroneous results.  Here is what I do ...
          .if eax                       ; If searching backward ...
            inv  SendMessage, hREd, EM_SETSEL, 0, 0 ; Get selected text
            mov  ft.chrg.cpMin, 0      ; Start position
            mov  ft.chrg.cpMax, -1      ; End position
          .else                        ; If searching forward ...
            inv  SendMessage, hREd, WM_GETTEXTLENGTH, 0, 0  ; Get text length
            mov  ft.chrg.cpMin, eax    ; Store it as current position
            mov  ft.chrg.cpMax, 0      ; Clear max position
          .endif                        ; End of conditional

Notice that I use WM_GETTEXTLENGTH instead of EM_GETTEXTLENGTHEX

Paul
Posted on 2006-05-23 07:58:13 by PBrennick
Paul,
I was just trying to get the size of a buffer needed to stream the text to, from the rich edit control.
I was experimenting, to see what effect the various flags had on the returned result, from a  EM_GETTEXTLENGTHEX message.
    According to the 2003 Platform SDK for the GETTEXTLENGTHEX structure, flags member,
"GTL_DEFAULT
Returns the number of characters. This is the default."
"GTL_NUMBYTES
Returns the number of bytes. This flag cannot be used with the GTL_NUMCHARS flag. E_INVALIDARG will be returned if both are used."

So I reasoned that if I streamed plain text, not unicode or rtf,into the rich edit control. And if I set the flags member of the GETTEXTLENGTHEX structure to either of those two flags before sending the EM_GETTEXTLENGTHEX message, the two returned values should be the same since the size of a plain text char is 1 byte.
The values are identical for rich edit v1, but not for rich edit v2,  the byte value is double the char value. This leads me to believe that internally, rich edit v2 and higher, treats ALL text as unicode.But I don't know I am correct in this thinking.
I am aware of the WM_GETTEXTLENGTH and used it before with regular edit controls.
But I have'nt used a rich edit ctl before, so I was looking in my 2003 Platform SDK, when I came across the EM_GETTEXTLENGTHEX message.
BTW Paul What HEX flag?
Rags
Posted on 2006-05-23 09:34:25 by rags
EM_GETTEXTLENGTHEX is used to get a hex count and a UNICODE count as both are tw characters wide which is the reason for the EX on the end.  EM_GETTEXTLENGTHEX returns a one character count.  Is that what you are searching for?  It is good to learn things just t know but I would stick with EM_GETTEXTLENGTH for Normal Text and EM_GETTEXTLENGTHEX for all others.  Since most of your use will be normal text it makes sense to not use the 'EX' ending.

Paul
Posted on 2006-05-23 10:30:57 by PBrennick
In the MSDN about EM_GETTEXTLENGTHEX it states:



Remarks

This message is a fast and easy way to determine the number of characters in the Unicode
version of the rich edit control. However, for a non-Unicode target code page you will
potentially be converting to a combination of single-byte and double-byte characters.



so it is for Unicode

Zcoder....
Posted on 2006-05-23 11:53:21 by Zcoder
ZCoder,
Those remarks definitely says it all in that if you use a UNICODE declaration on a non-UNICODE target ...

Paul
Posted on 2006-05-23 12:42:52 by PBrennick