Solved

Word wrap in CEdit control

Posted on 2001-06-05
8
5,723 Views
Last Modified: 2013-11-20
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
Comment
Question by:sindbad
8 Comments
 
LVL 1

Expert Comment

by:Black_End
Comment Utility
Read about EM_FMTLINES and CEdit::FmtLines
0
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
Comment Utility
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
 
LVL 1

Expert Comment

by:tvanceplus
Comment Utility
jkr is right. I use CEdit controls with edit resources with that facility all the time to get the user to enter text.
0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
  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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
> The ES_AUTOHSCROLL style

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

-=- James.
0
 
LVL 1

Expert Comment

by:tvanceplus
Comment Utility
i think i misread your question. sorry.
0
 

Author Comment

by:sindbad
Comment Utility

Yes JKR,

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

Sindbad
0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
Entropy abounds... :(

-=- James.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now