Discussion:
How to limit the rich edit control text
(too old to reply)
KJ
2010-02-20 09:40:04 UTC
Permalink
Hi Friends!

I need your help to fix a problem, which I faced in my application. In
my application I have rich edit control, Whose limit I set to be say
2000 character. When I was typing the text its not taking a single
character also more then my limit. But if I copy text from some note
pad file and try to copy its copying more charater then my limit.

I used EM_LIMITTEXT to set the limit to my control, I also tried with
EM_EXLIMITTEXT and EM_SETTEXTLIMIT.

Due to this what problem I am getting is?.. In some Xp systems Its not
retriving the text from the contorl. Then I used the EM_GETTEXTEX and
retrived the text. And then if I tried to set this text again to a
simillar kind of control
whose limit is also same and it is also in the same dailog.

So...
Please some one give me a perfect solution for this problem I
will realy appriciate for this help.
Rene Pilon
2010-02-23 22:38:45 UTC
Permalink
Hi KJ,

you'll have to subclass your richedit window and handle the WM_PASTE message
as well - you'll also have to now handle what happens when the user drags
and drops text into your richedit.


Regards,

Rene Pilon
Rene Pilon
2010-02-23 22:40:16 UTC
Permalink
To add to my previous post - before allowing the paste or drop operation to
succeed - you will have to count the current number of characters in your
richedit - and then count the number of characters that will be pasted /
dropped - and decide what to do from there.

Regards,

Rene Pilon
KJ
2010-02-25 04:54:13 UTC
Permalink
Post by Rene Pilon
To add to my previous post - before allowing the paste or drop operation to
succeed - you will have to count the current number of characters in your
richedit - and then count the number of characters that will be pasted /
dropped - and decide what to do from there.
Regards,
Rene Pilon
Thanks for your replay Rene Pilon,

I think this mehtod will work but I dont know how I can know the
number of charaters that will be pasted.
Can you please let me know how I can get the characters count of the
text, that we are trying to past.

Regards,
KJ
Rene Pilon
2010-02-27 16:20:55 UTC
Permalink
Hi KJ,

When you receive the WM_PASTE message - you'll have to check the clipboard
for the format ( CF_TEXT, CF_? - do a search for available clipboard
formats) that you will be accepting into your richtext window. (do a search
for OpenClipboard, GetClipboardData, etc....) This is where you determine
what is in the clipboard (ie format, and size of data) - from there - you
can append the text to your richedit (and limit what you append).

In your wndproc you would capture the WM_PASTE message, do what you want
with the clipboard data awaiting to be pasted in your richedit, and then -
return instead of allowing the defaulf window procedure to process the
WM_PASTE message.

You may also want to do further research on items such as EM_STREAMIN et
al.....

Regards,

Rene.
Post by Rene Pilon
To add to my previous post - before allowing the paste or drop operation to
succeed - you will have to count the current number of characters in your
richedit - and then count the number of characters that will be pasted /
dropped - and decide what to do from there.
Regards,
Rene Pilon
Thanks for your replay Rene Pilon,

I think this mehtod will work but I dont know how I can know the
number of charaters that will be pasted.
Can you please let me know how I can get the characters count of the
text, that we are trying to past.

Regards,
KJ

Loading...