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. Change in rich edit control behaviour with EM_EXSETSEL / SetSel

Change in rich edit control behaviour with EM_EXSETSEL / SetSel

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 3 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.
  • P Offline
    P Offline
    Paul Vickery
    wrote on last edited by
    #1

    There seems to have been a change in behaviour between VC6 and VS2005 builds when calling SetSel / EM_EXSETSEL in a rich edit control. I have code which emboldens certain lines of text, which used to work in VC6, but since moving to VS2005 has come up with the wrong results. The code is something like:

    CString sText;
    pEdit->GetWindowText(sText);

    CString sSection = "SectionHeading";
    int nPos = sText.Find(sSection);
    int nPosEnd = nPos + sSection.GetLength();
    pEdit->SetSel(nPos, nPosEnd);

    If the heading is at the start of the text, then it's ok, else the selection is offset by the number of lines, which makes we think that the old code counted line breaks as two characters, but the new code counts a line break as one character. In the sText, the line breaks are definately two characters in both VC6 and VS8 builds. Any ideas anyone?


    "The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)

    V M 2 Replies Last reply
    0
    • P Paul Vickery

      There seems to have been a change in behaviour between VC6 and VS2005 builds when calling SetSel / EM_EXSETSEL in a rich edit control. I have code which emboldens certain lines of text, which used to work in VC6, but since moving to VS2005 has come up with the wrong results. The code is something like:

      CString sText;
      pEdit->GetWindowText(sText);

      CString sSection = "SectionHeading";
      int nPos = sText.Find(sSection);
      int nPosEnd = nPos + sSection.GetLength();
      pEdit->SetSel(nPos, nPosEnd);

      If the heading is at the start of the text, then it's ok, else the selection is offset by the number of lines, which makes we think that the old code counted line breaks as two characters, but the new code counts a line break as one character. In the sText, the line breaks are definately two characters in both VC6 and VS8 builds. Any ideas anyone?


      "The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)

      V Offline
      V Offline
      Vaclav_
      wrote on last edited by
      #2

      While working with rich edit I found out that setting the selection back to begining is often necessary. Since I work with VC6 I cannot comment on the "rest of the story". Cheers Vaclav

      P 1 Reply Last reply
      0
      • P Paul Vickery

        There seems to have been a change in behaviour between VC6 and VS2005 builds when calling SetSel / EM_EXSETSEL in a rich edit control. I have code which emboldens certain lines of text, which used to work in VC6, but since moving to VS2005 has come up with the wrong results. The code is something like:

        CString sText;
        pEdit->GetWindowText(sText);

        CString sSection = "SectionHeading";
        int nPos = sText.Find(sSection);
        int nPosEnd = nPos + sSection.GetLength();
        pEdit->SetSel(nPos, nPosEnd);

        If the heading is at the start of the text, then it's ok, else the selection is offset by the number of lines, which makes we think that the old code counted line breaks as two characters, but the new code counts a line break as one character. In the sText, the line breaks are definately two characters in both VC6 and VS8 builds. Any ideas anyone?


        "The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Have you tried using EM_FINDTEXT to find the text position instead of copying the text to a CString? Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        P 1 Reply Last reply
        0
        • V Vaclav_

          While working with rich edit I found out that setting the selection back to begining is often necessary. Since I work with VC6 I cannot comment on the "rest of the story". Cheers Vaclav

          P Offline
          P Offline
          Paul Vickery
          wrote on last edited by
          #4

          Thanks for your reply. It's not that - I've found it: VC6 used RichEdit 1.0 controls by default, whereas VS8 uses RichEdit 2.0 controls by default, so that is where the difference lies. Version 1.0 seems to count line breaks as 2 chars, whereas 2.0 counts them as 1 char. I was getting my positions from my CString, which contains CR+LFs so counts line breaks as 2 chars. I have changed my code to use the Find facility (EM_FINDTEXT/EM_FINDTEXTEX) in the RichEdit control, and all is now OK. (Not really sure why I didn't just use that in the first place!)


          "The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)

          V 1 Reply Last reply
          0
          • P Paul Vickery

            Thanks for your reply. It's not that - I've found it: VC6 used RichEdit 1.0 controls by default, whereas VS8 uses RichEdit 2.0 controls by default, so that is where the difference lies. Version 1.0 seems to count line breaks as 2 chars, whereas 2.0 counts them as 1 char. I was getting my positions from my CString, which contains CR+LFs so counts line breaks as 2 chars. I have changed my code to use the Find facility (EM_FINDTEXT/EM_FINDTEXTEX) in the RichEdit control, and all is now OK. (Not really sure why I didn't just use that in the first place!)


            "The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)

            V Offline
            V Offline
            Vaclav_
            wrote on last edited by
            #5

            Paul, After I posted my reply I realized that I was responding incorrectly. Anyway, I observed same "problem" - I was searching for string and not counting the space after the string. Consequently my display was off few characters. ( I was changing the text color) By accident - and I am sure you are aware of that - if you search rich text control for string using substring search it will give you the first match and it may not be what you are looking for. Cheers Vaclav

            1 Reply Last reply
            0
            • M Mark Salsbery

              Have you tried using EM_FINDTEXT to find the text position instead of copying the text to a CString? Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              P Offline
              P Offline
              Paul Vickery
              wrote on last edited by
              #6

              I have now! See my other reply. Thanks.


              "The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)

              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