Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CEdit carriage returns

CEdit carriage returns

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelpdata-structures
17 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J John R Shaw

    I have not used an multiline edit control for a while, but if you are reading in a file from disk and getting 'square' boxes. Then you probubly need to strip out the the CRs and just end the lines with LF. If this is the case, and you want to write the text back to disk, you may need to insert the CRs back into the text before saving. INTP

    S Offline
    S Offline
    scontapay
    wrote on last edited by
    #6

    Thanks I thought that is what I had todo, but I figured their would have been a helper function or a member of CString todo that since it sounds like something a lot of people would do. Oh well time to write a small search and replace function :)

    J S 2 Replies Last reply
    0
    • S scontapay

      Sorry should have been more clear but thanks for the fast response. I am not adding the '\r\n' or anything into the code, it is how it is getting read into the buffer from the member function. I'll post an example when I get home from the code I have but basically its: Create CInternetSession and CHttpFile, send request, and then the read member function from CHttpFile. Then I just call SetDlgItemText(IDC_EDIT, strBuff); Where strBuff is a CString that has been created using the character array CString strBuff(Buffer); I know its redundant but I did this to see if CString would handle the carriage return better but its not :(

      S Offline
      S Offline
      Shay Harel
      wrote on last edited by
      #7

      Well then, Once again, on the same string you send to the edit box, try : strBuff.Remove ('\r'); See if that will work.

      S 1 Reply Last reply
      0
      • S Shay Harel

        Well then, Once again, on the same string you send to the edit box, try : strBuff.Remove ('\r'); See if that will work.

        S Offline
        S Offline
        scontapay
        wrote on last edited by
        #8

        Ah sorry misread your post. I thought you meant not for me to write it into the buffer, which I wasn't. I need some coffee :( I will try that thank you, and thank you for your patience!

        1 Reply Last reply
        0
        • S scontapay

          Hi I have a CEdit control that I am trying to have multilined. I am reading a file into a char array buffer: char buffer[1000]; CClass->Read(Buffer, length); My question is that when I have the edit box display the buffer it is not displaying it correctly. Instead of carriage returns I am getting 'square' boxes. I moved the buffer into a CString, but its not picking up the CRLF. How do I go about doing this? Do I have to search and replace? Or, is there a CString method that easily fixes the CRLF problem I am having. I tried using the character array and a type-casted CString variable but I keep getting the same problem. The class I am using is CHttpFile and its read method. TIA for any help or insight you can give into this matter.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #9

          Make sure the control has the ES_MULTILINE style.

          S 1 Reply Last reply
          0
          • D David Crow

            Make sure the control has the ES_MULTILINE style.

            S Offline
            S Offline
            scontapay
            wrote on last edited by
            #10

            Its set to true. Btw I am using Visual Studio.Net the first release, and I can't believe that it does not have a single service pack or update for it.

            D 1 Reply Last reply
            0
            • S scontapay

              Its set to true. Btw I am using Visual Studio.Net the first release, and I can't believe that it does not have a single service pack or update for it.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #11

              Then the following code snippet should work: m_edit.SetWindowText("This is on line 1\r\nThis is on line 2\r\nThis is on line 3");

              S 1 Reply Last reply
              0
              • S scontapay

                Thanks I thought that is what I had todo, but I figured their would have been a helper function or a member of CString todo that since it sounds like something a lot of people would do. Oh well time to write a small search and replace function :)

                J Offline
                J Offline
                John R Shaw
                wrote on last edited by
                #12

                There normaly is but you did not say what class you is providing the read method. CArchive provides ReadString() (reads one line at a time), although I think it removeS the CRLF and replaces it with a '\0'. If using stdio (C) then you would use fgets() replaces the CRLF with '\n''\0'. So you may, or may not, already have a method that will help you. INTP

                1 Reply Last reply
                0
                • D David Crow

                  Then the following code snippet should work: m_edit.SetWindowText("This is on line 1\r\nThis is on line 2\r\nThis is on line 3");

                  S Offline
                  S Offline
                  scontapay
                  wrote on last edited by
                  #13

                  DavidCrow yes that would work thank you. But the enformation I am getting is placed inside a buffer which is a CString, and it is that CString I am putting into the edit box, for example: SetDlgItemText(IDC_EDIT, strBuffer); Where strBuffer is a CString, and the information from that is read from a file. Once placed inside the CEdit box it is displaying those weird 'squares' instead of doing a CRLF.

                  D 1 Reply Last reply
                  0
                  • S scontapay

                    DavidCrow yes that would work thank you. But the enformation I am getting is placed inside a buffer which is a CString, and it is that CString I am putting into the edit box, for example: SetDlgItemText(IDC_EDIT, strBuffer); Where strBuffer is a CString, and the information from that is read from a file. Once placed inside the CEdit box it is displaying those weird 'squares' instead of doing a CRLF.

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #14

                    It matters not that SetWindowText()'s parameter is a CString, or a string literal. The characters \r\n must be used. If you are only receiving one of them, a quick search and replace is all that's needed. For example: CString str = "This is on line 1\rThis is on line 2\rThis is on line 3"; str.Replace("\r", "\r\n"); m_edit.SetWindowText(str);

                    S 1 Reply Last reply
                    0
                    • S scontapay

                      Thanks I thought that is what I had todo, but I figured their would have been a helper function or a member of CString todo that since it sounds like something a lot of people would do. Oh well time to write a small search and replace function :)

                      S Offline
                      S Offline
                      Shog9 0
                      wrote on last edited by
                      #15

                      scontapay wrote: I figured their would have been a helper function or a member of CString strTextWithCarriageReturns::Remove(_T('\r'));

                      Shog9

                      Give me a Leonard Cohen afterworld So I can sigh enternally...

                      S 1 Reply Last reply
                      0
                      • S Shog9 0

                        scontapay wrote: I figured their would have been a helper function or a member of CString strTextWithCarriageReturns::Remove(_T('\r'));

                        Shog9

                        Give me a Leonard Cohen afterworld So I can sigh enternally...

                        S Offline
                        S Offline
                        scontapay
                        wrote on last edited by
                        #16

                        Thanks I see where my problem is. It is the fact that I kept misreading everyones advice :( I thought everyone was trying to tell me to insert it into the buffer I was creating, and didn't think anyone knew I was reading it in. My fault... See what 6-8 months away does to a C++ programmer when programminging VB! :|

                        1 Reply Last reply
                        0
                        • D David Crow

                          It matters not that SetWindowText()'s parameter is a CString, or a string literal. The characters \r\n must be used. If you are only receiving one of them, a quick search and replace is all that's needed. For example: CString str = "This is on line 1\rThis is on line 2\rThis is on line 3"; str.Replace("\r", "\r\n"); m_edit.SetWindowText(str);

                          S Offline
                          S Offline
                          scontapay
                          wrote on last edited by
                          #17

                          I wanted to thank you for your help. Here is a copy of a post made above so you know what happened: Thanks I see where my problem is. It is the fact that I kept misreading everyones advice I thought everyone was trying to tell me to insert it into the buffer I was creating, and didn't think anyone knew I was reading it in. My fault... See what 6-8 months away does to a C++ programmer when programminging VB! :|

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups