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 problem in displaying CR and LF [modified]

CEdit problem in displaying CR and LF [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structures
9 Posts 4 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.
  • B Offline
    B Offline
    bhanu_8509
    wrote on last edited by
    #1

    Dear All, I am using CEdit to display a text in an array like below :

    wchar_t szData[5];
    szData[0] = 'a';
    szData[1] = 'b';
    szData[2] = 'c';
    szData[3] = '\r';
    szData[4] = '\0';
    m_EDIT.ReplaceSel(szData);//even I tried with SetWindowTextW

    But, when I display the contents, the CR is displaying as boxes, even I tried with '\n' and the result is the same. Since, it is displaying as a box, further text is not displayed on the next line and it is printed in the same line with boxes after every "abc". Please help to solve the issue.

    modified on Tuesday, August 25, 2009 5:15 AM

    C R 2 Replies Last reply
    0
    • B bhanu_8509

      Dear All, I am using CEdit to display a text in an array like below :

      wchar_t szData[5];
      szData[0] = 'a';
      szData[1] = 'b';
      szData[2] = 'c';
      szData[3] = '\r';
      szData[4] = '\0';
      m_EDIT.ReplaceSel(szData);//even I tried with SetWindowTextW

      But, when I display the contents, the CR is displaying as boxes, even I tried with '\n' and the result is the same. Since, it is displaying as a box, further text is not displayed on the next line and it is printed in the same line with boxes after every "abc". Please help to solve the issue.

      modified on Tuesday, August 25, 2009 5:15 AM

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      First, there's an error in your code: you are not increasing the index. Is it only a typpo ? Second, you need to have both the carriage return and newline characters (I don't remember in which order, you'll need to test it).

      Cédric Moonen Software developer
      Charting control [v2.0] OpenGL game tutorial in C++

      B 1 Reply Last reply
      0
      • C Cedric Moonen

        First, there's an error in your code: you are not increasing the index. Is it only a typpo ? Second, you need to have both the carriage return and newline characters (I don't remember in which order, you'll need to test it).

        Cédric Moonen Software developer
        Charting control [v2.0] OpenGL game tutorial in C++

        B Offline
        B Offline
        bhanu_8509
        wrote on last edited by
        #3

        I am really sorry Cedric Moonen. It is a typing mistake in my previous message (now corrected it).

        Cedric Moonen wrote:

        Second, you need to have both the carriage return and newline characters

        I agree with your comment, when I use \r\n then it is displaying in the nextline but my real problem is that my input text will come like the following :

        "abc\rxyz\rpqr\r"

        C 1 Reply Last reply
        0
        • B bhanu_8509

          I am really sorry Cedric Moonen. It is a typing mistake in my previous message (now corrected it).

          Cedric Moonen wrote:

          Second, you need to have both the carriage return and newline characters

          I agree with your comment, when I use \r\n then it is displaying in the nextline but my real problem is that my input text will come like the following :

          "abc\rxyz\rpqr\r"

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          Then you will need to convert it so that all the \r sequences are replaced by \r\n sequences. std::string and CString have functions to do that.

          Cédric Moonen Software developer
          Charting control [v2.0] OpenGL game tutorial in C++

          B 1 Reply Last reply
          0
          • B bhanu_8509

            Dear All, I am using CEdit to display a text in an array like below :

            wchar_t szData[5];
            szData[0] = 'a';
            szData[1] = 'b';
            szData[2] = 'c';
            szData[3] = '\r';
            szData[4] = '\0';
            m_EDIT.ReplaceSel(szData);//even I tried with SetWindowTextW

            But, when I display the contents, the CR is displaying as boxes, even I tried with '\n' and the result is the same. Since, it is displaying as a box, further text is not displayed on the next line and it is printed in the same line with boxes after every "abc". Please help to solve the issue.

            modified on Tuesday, August 25, 2009 5:15 AM

            R Offline
            R Offline
            Rajesh R Subramanian
            wrote on last edited by
            #5

            bhanu_8509 wrote:

            wchar_t szData[5]; szData[0] = 'a'; szData[1] = 'b'; szData[2] = 'c'; szData[3] = '\r'; szData[4] = '\0';

            I don't see the purpose behind populating each and every element in a string separately. May be you haven't known of functions like strcpy? This would work for both Unicode and MBCS builds:

            TCHAR szData[4];
            _tcscpy(szData, _T("abc"));
            m_EDIT.SetWindowText(szData);

            For entering a new line, use \r\n and make sure that in the properties of the edit box, "multiline" is set to true.

            It is a crappy thing, but it's life -^ Carlo Pallini

            modified on Tuesday, August 25, 2009 6:44 AM

            CPalliniC 1 Reply Last reply
            0
            • R Rajesh R Subramanian

              bhanu_8509 wrote:

              wchar_t szData[5]; szData[0] = 'a'; szData[1] = 'b'; szData[2] = 'c'; szData[3] = '\r'; szData[4] = '\0';

              I don't see the purpose behind populating each and every element in a string separately. May be you haven't known of functions like strcpy? This would work for both Unicode and MBCS builds:

              TCHAR szData[4];
              _tcscpy(szData, _T("abc"));
              m_EDIT.SetWindowText(szData);

              For entering a new line, use \r\n and make sure that in the properties of the edit box, "multiline" is set to true.

              It is a crappy thing, but it's life -^ Carlo Pallini

              modified on Tuesday, August 25, 2009 6:44 AM

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              You're were out-of-bounds again! ;P :laugh:

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              In testa che avete, signor di Ceprano?

              R 1 Reply Last reply
              0
              • CPalliniC CPallini

                You're were out-of-bounds again! ;P :laugh:

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                R Offline
                R Offline
                Rajesh R Subramanian
                wrote on last edited by
                #7

                OK OK... :)

                It is a crappy thing, but it's life -^ Carlo Pallini

                CPalliniC 1 Reply Last reply
                0
                • R Rajesh R Subramanian

                  OK OK... :)

                  It is a crappy thing, but it's life -^ Carlo Pallini

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #8

                  OK OK... :) :laugh:

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  In testa che avete, signor di Ceprano?

                  1 Reply Last reply
                  0
                  • C Cedric Moonen

                    Then you will need to convert it so that all the \r sequences are replaced by \r\n sequences. std::string and CString have functions to do that.

                    Cédric Moonen Software developer
                    Charting control [v2.0] OpenGL game tutorial in C++

                    B Offline
                    B Offline
                    bhanu_8509
                    wrote on last edited by
                    #9

                    Dear Cedric, Thank you so much now I solved the proble but only one thing is pending. For instance, if the text has more no. of \r in it then how could I replace all the \r. Please give me your advice. I have done already for one occurance of \r and the code is below.

                    char *str = "abc\rxyz";
                    stdstr = str;
                    int idx = stdstr.find('\r');
                    stdstr.insert((idx+1),1,'\n');
                    const char* rcData = stdstr.c_str();
                    int lenA = lstrlenA(rcData);
                    int lenW;
                    wchar_t *unircData;
                    lenW = ::MultiByteToWideChar(CP_ACP,0,rcData,lenA,0,0);
                    unircData = SysAllocStringLen(0,lenW);
                    if(lenW >0)
                    {
                    ::MultiByteToWideChar(CP_ACP,0,rcData,lenA,unircData,lenW);
                    }
                    unircData[lenW] = 0;
                    m_EDIT.ReplaceSel(unircData);

                    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