How to add a newline with SetWindowText() in ReadOnly CEdit? "\n" doesn't work :(
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: How to add a newline with SetWindowText() in ReadOnly CEdit? "\n" doesn't work :(

  1. #1
    Join Date
    May 2001
    Location
    Oslo, Norway
    Posts
    610

    How to add a newline with SetWindowText() in ReadOnly CEdit? "\n" doesn't work :(

    I made some simple log window out of CEdit control. It is read only , or i would say output only. User cannot input text, only see logging. But program must be able to write text out to this console. I use GetWindowText() and SetWindowText() as described. And newline is supposed to be done by adding "\n" at the end of lines, doesn't it ??? Well it doesn't work with CEdit. It prints out some strange "l" or "i" symbol instead of a newline... Any clue? Logging is supposed to be multilined, you know

    Thanks in advance you mighty coders


  2. #2
    igbrus is offline Elite Member Power Poster
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4,658

    Re: How to add a newline with SetWindowText() in ReadOnly CEdit? "\n" doesn't work :(

    What about"\r\n"?

    Rating isn't important...But gurus respect it and keep high

  3. #3
    Join Date
    Mar 2000
    Location
    Bangalore,India
    Posts
    776

    Re: How to add a newline with SetWindowText() in ReadOnly CEdit? "\n" doesn't work :(

    hi
    try this instead of \r\n

    CEdit *myEdit=(CEdit *)GetDlgItem(IDC_EDIT1);
    myEdit->SetWindowText("My 1st Line \r\nMy 2nd Line");

    Regards
    SKP

    Be sure to rate answers if it helped, to encourage them.

  4. #4
    Join Date
    Jan 2013
    Posts
    1

    Re: How to add a newline with SetWindowText() in ReadOnly CEdit? "\n" doesn't work :

    And don't forget to set the edit control property 'Multiline' to True!

  5. #5
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    Re: How to add a newline with SetWindowText() in ReadOnly CEdit? "\n" doesn't work :

    Just to complete the answers already posted, have a look in this FAQ: How to append text to an edit control?
    If you want add lines to a multiline edit control, it's much better to use CEdit::SetSel and CEdit::ReplaceSel instead of CWnd::GetWindowText and CWnd::SetWindowText.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center