Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Multiple lines in a simple CEdit control

4,434 views
Skip to first unread message

strat...@gmail.com

unread,
Mar 28, 2008, 11:49:06 AM3/28/08
to
I am trying to do something that seems like it should be simple but...

I am trying to write a multi-line string into an edit control on a
dialog box. I form the CString by putting a \n between substrings of
text. If I use CWnd::DrawText, the result works as desired, i.e.

string1
string 2
etc

If I use SetWindowText, the \n is not interpreted as a newline but
just another character and I get a single line of text. Is there
another way to add newlines in SetWindowText strings?

Thanks in advance.
Bob

AliR (VC++ MVP)

unread,
Mar 28, 2008, 11:47:18 AM3/28/08
to
Did you set the ES_MULTILINE flag of the edit control? You can do that from
the resource editor by setting the Multiline property to TRUE.

Also if you want the user to be able to press Enter in your edit control to
insert a new line you might want to set the ES_WANTRETURN (Want Return
propety in resource editor).

AliR.


<strat...@gmail.com> wrote in message
news:eb005e0c-b75c-4e3e...@e39g2000hsf.googlegroups.com...

David Ching

unread,
Mar 28, 2008, 11:57:42 AM3/28/08
to
<strat...@gmail.com> wrote in message
news:eb005e0c-b75c-4e3e...@e39g2000hsf.googlegroups.com...
> If I use SetWindowText, the \n is not interpreted as a newline but
> just another character and I get a single line of text. Is there
> another way to add newlines in SetWindowText strings?
>

I'm not sure, but instead of \n, try putting \r\n.

-- David


Joseph M. Newcomer

unread,
Mar 28, 2008, 12:09:54 PM3/28/08
to
Since it is an edit control, painting it yourself is inappropriate, so it doesn't matter
if it gives the illusion of working correctly, Don't Do That.

It requires \r\n for SetWindowText.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

AliR (VC++ MVP)

unread,
Mar 28, 2008, 12:06:18 PM3/28/08
to
hehe, forgot about the \r. :)

AliR.


"David Ching" <d...@remove-this.dcsoft.com> wrote in message
news:Wz8Hj.36355$J41....@newssvr14.news.prodigy.net...

strat...@gmail.com

unread,
Mar 28, 2008, 12:25:01 PM3/28/08
to
On Mar 28, 9:06 am, "AliR \(VC++ MVP\)" <A...@online.nospam> wrote:
> hehe, forgot about the \r. :)
>
> AliR.
>
> "David Ching" <d...@remove-this.dcsoft.com> wrote in message
>
> news:Wz8Hj.36355$J41....@newssvr14.news.prodigy.net...
>
>
>
> > <stratpi...@gmail.com> wrote in message

> >news:eb005e0c-b75c-4e3e...@e39g2000hsf.googlegroups.com...
> >> If I use SetWindowText, the \n is not interpreted as a newline but
> >> just another character and I get a single line of text.  Is there
> >> another way to add newlines in SetWindowText strings?
>
> > I'm not sure, but instead of \n, try putting \r\n.
>
> > -- David- Hide quoted text -
>
> - Show quoted text -

Thanks all. The \r solved the problem. I guess it helps to read the
documentation :-)

Bob

0 new messages