Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6049
  • Last Modified:

Word wrap in CEdit control

Hi,

I'm having a MFC Dialog application that has an edit control (CEdit). This control can accept a maximum of 250 characters. This control is multiline and can accept a maximum of 40 characters per line.

As the user keys in text, I need a mechanism to wrap the text after every 40 characters to a new line. CEdit don't seems to support this directly.

Can anyone help me to implement my requirement ?.
Will CRichEditCtrl be of any help ?

Thanks,
sindbad



0
sindbad
Asked:
sindbad
1 Solution
 
Black_EndCommented:
Read about EM_FMTLINES and CEdit::FmtLines
0
 
jkrCommented:
All you have to do is removing 'ES_AUTOHSCROLL' from the edit control, and it'll handle the word wrap
by itself. Try that in the resource editor.
0
 
tvanceplusCommented:
jkr is right. I use CEdit controls with edit resources with that facility all the time to get the user to enter text.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
jtwine100697Commented:
  EM_FMTLINES is only used to specify the inclusion of "soft breaks" in the actual text buffer of the control to match the breaks visible on-screen.

   The ES_AUTOHSCROLL style only causes lines to break when they hit the visible limits of the edit control.  So using a smaller font will change the "break" behavior.

   If you only need the text broken up into "lines of 40 characters or less" for some kind of processing AFTER the user enters the data, then why not manually break up the text after the user is finished entering it?  Or is there a requirement that it has to be broken while being entered in your interface?

   You *MAY* be able to use EM_SETWORDBREAKPROC to specify your own word-break function, and "backing-up" in the text stream (on a line-by-line basis) looking for the end of a word before or at character position 40, when you get a callback for "WB_LEFT".  No promises, though...

-=- James.
0
 
jtwine100697Commented:
> The ES_AUTOHSCROLL style

   Oops.  That should read "Removing the ES_AUTOHSCROLL style".

-=- James.
0
 
tvanceplusCommented:
i think i misread your question. sorry.
0
 
sindbadAuthor Commented:

Yes JKR,

It works. Oh, such a simple solution.
Thanks,

Sindbad
0
 
jtwine100697Commented:
Entropy abounds... :(

-=- James.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now