I'm looking to make a basic edit box word wrap the text in it. I've resized the edit box control to a decent size and I'd like to have the text that is typed into it word wrap. I'm using Visual Studio 2010 and I've set the multiline property to true. Searching online for this yields search results about how to set word wrap properties within the Visual Studio program, not in my actual edit control. I may be getting close with results like EditWordBreakProc and EM_SETWORDBREAKPROC but I'm not finding how to use them.
I ended up creating my own class that handles text functions like word wrapping and font changes.
If you were to go that way then you would probably want to know about GetTextExtentPoint32() which basically looks at an hdc and tells you how long and how high your string is in pixels.
EditWordBreakProc and EM_SETWORDBREAKPROC is the right way to go.
Google is surprisingly quiet on this subject. naraku9333 has already pointed you at the MSDN Knowledge base article. There is another example on this page:
It's the kind of thing I expected to be present on codeproject.com or codeguru.com, but I didn't get any useful hits from either of these places (both usually good places for this kind of thing, even if the people there are over fond of MFC...)
The default wordwrap function breaks a line in a multiline edit control (MLE) at a space character.
What I am trying to figure out is if that is the default behavior, is there a setting I'm missing somewhere? Because the code on that page is custom code to get the edit control to wordwrap at the ~ character. Still, I tried to implement it (and replaced the ~ with a space in the code) with no luck. I'm thinking that I put everything where it was supposed to go from that page except for the WordBreakProc function. I put the prototype at the top, I put the SetDlgItemMessage under WM_INITDIALOG and I put the WordBreakProc function at the bottom of the page. I'm a little fuzzy there on where exactly it is supposed to go.
At any rate, when I try to use that code, I get the message that lpWrdBrkProc was undefined. I'm not sure what lpWrdBrkProc is or where it is supposed to come from but the code on that page doesn't have it declared anywhere.
I've also tried using this line from the yezhucn link:
No luck there either. There isn't a WordBreakProc function on that page so I used the one from the first link.
I'm not sure what to do from here. Over the past month I have been getting to where I can (just!) understand how to utilize sample code and tweak it to suit my needs.
Note the "want return" setting doesn't effect the line breaking. But it does determine whether the return key insert a line break or clicks the default push button.