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. Non display characters for selection count

Non display characters for selection count

Scheduled Pinned Locked Moved C / C++ / MFC
21 Posts 5 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.
  • F ForNow

    I was referring to richedit when determining the selection position

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

    So you are taking whatever text is already present in the edit control and adding CRLF to the end of it? I'm trying to ascertain if this is an appending issue (I've seen some weird ways in which folks try to append to an edit control) or something else.

    "One man's wage rise is another man's price increase." - Harold Wilson

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

    F 1 Reply Last reply
    0
    • D David Crow

      So you are taking whatever text is already present in the edit control and adding CRLF to the end of it? I'm trying to ascertain if this is an appending issue (I've seen some weird ways in which folks try to append to an edit control) or something else.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      F Offline
      F Offline
      ForNow
      wrote on last edited by
      #7

      For Crlf which is 2 bytes in memory aka the buffer I count 1 for determining the selection count

      D 1 Reply Last reply
      0
      • F ForNow

        For Crlf which is 2 bytes in memory aka the buffer I count 1 for determining the selection count

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

        But are taking whatever text is already present in the edit control and adding CRLF to the end of it?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        F 1 Reply Last reply
        0
        • D David Crow

          But are taking whatever text is already present in the edit control and adding CRLF to the end of it?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #9

          The text is included in the count for the cold I count as 1 character for porpouses of selection not 2 bytes

          D L 2 Replies Last reply
          0
          • F ForNow

            The text is included in the count for the cold I count as 1 character for porpouses of selection not 2 bytes

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

            I misunderstood what you were attempting. You are using the GetSel() method to get the starting and ending positions of the control's selected text, correct? I tried that and with all of the text in the control selected, I found that CR and LF are (like I would expect) considered two separate characters. In other words, start = 0 and end = 7.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            F 1 Reply Last reply
            0
            • D David Crow

              I misunderstood what you were attempting. You are using the GetSel() method to get the starting and ending positions of the control's selected text, correct? I tried that and with all of the text in the control selected, I found that CR and LF are (like I would expect) considered two separate characters. In other words, start = 0 and end = 7.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              F Offline
              F Offline
              ForNow
              wrote on last edited by
              #11

              I use the Streamout api to get whatever is in the control the edit control has 4 lines at the end of each line is X0D0A CRLF I have to count the 0X0D0A as 1 character for the SetSel api when determining the pos I want to use in the selection thanks

              D 1 Reply Last reply
              0
              • F ForNow

                I use the Streamout api to get whatever is in the control the edit control has 4 lines at the end of each line is X0D0A CRLF I have to count the 0X0D0A as 1 character for the SetSel api when determining the pos I want to use in the selection thanks

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

                So your end game is just to programmatically insert/replace some characters some place in the edit control?

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                F 1 Reply Last reply
                0
                • F ForNow

                  The text is included in the count for the cold I count as 1 character for porpouses of selection not 2 bytes

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #13

                  I just tried this with an ordinary Edit control, and it returns both CR LF in the count.

                  B 1 Reply Last reply
                  0
                  • D David Crow

                    So your end game is just to programmatically insert/replace some characters some place in the edit control?

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                    F Offline
                    F Offline
                    ForNow
                    wrote on last edited by
                    #14

                    I have 16 pieces of text in the 4 line edit control any one of whom I could potentially replace

                    1 Reply Last reply
                    0
                    • L Lost User

                      The documentation at EM_GETSELTEXT message (Windows)[^] does not explicitly say whether it does, or does not. But a simple test should prove it one way or another.

                      B Offline
                      B Offline
                      Bram van Kampen
                      wrote on last edited by
                      #15

                      Well, This is Familiar, in particular with the multi threaded question you asked earlier. MFC cannot realy handle multiple threads. No one seems to know why, I have asked the question before. At any rate, the only way MFC objects can communicate between threads is with the Old Fashioned WDK Kernel Function ::SendMessage(hWnd, Param1,Param2); In MFC you create your Message as WM_USER+(X), Create a Message Handler, and, manually add it to the message map. Any attempt to call an MFC Object from a different thread than in which it was created always ultimately lead to failure. The Symptoms are: Works, Add a Virtual Function: It stops Working Hope this helps

                      Bram van Kampen

                      L D 2 Replies Last reply
                      0
                      • L Lost User

                        I just tried this with an ordinary Edit control, and it returns both CR LF in the count.

                        B Offline
                        B Offline
                        Bram van Kampen
                        wrote on last edited by
                        #16

                        You did not try this in a Multi Threaded Environment, as explained in the question previous of this :)

                        Bram van Kampen

                        L 1 Reply Last reply
                        0
                        • B Bram van Kampen

                          You did not try this in a Multi Threaded Environment, as explained in the question previous of this :)

                          Bram van Kampen

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #17

                          Sorry, but I am not sure what relevance that has to the counting of characters.

                          1 Reply Last reply
                          0
                          • B Bram van Kampen

                            Well, This is Familiar, in particular with the multi threaded question you asked earlier. MFC cannot realy handle multiple threads. No one seems to know why, I have asked the question before. At any rate, the only way MFC objects can communicate between threads is with the Old Fashioned WDK Kernel Function ::SendMessage(hWnd, Param1,Param2); In MFC you create your Message as WM_USER+(X), Create a Message Handler, and, manually add it to the message map. Any attempt to call an MFC Object from a different thread than in which it was created always ultimately lead to failure. The Symptoms are: Works, Add a Virtual Function: It stops Working Hope this helps

                            Bram van Kampen

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #18

                            ... and I don't think you meant to post this message to me.

                            B 1 Reply Last reply
                            0
                            • B Bram van Kampen

                              Well, This is Familiar, in particular with the multi threaded question you asked earlier. MFC cannot realy handle multiple threads. No one seems to know why, I have asked the question before. At any rate, the only way MFC objects can communicate between threads is with the Old Fashioned WDK Kernel Function ::SendMessage(hWnd, Param1,Param2); In MFC you create your Message as WM_USER+(X), Create a Message Handler, and, manually add it to the message map. Any attempt to call an MFC Object from a different thread than in which it was created always ultimately lead to failure. The Symptoms are: Works, Add a Virtual Function: It stops Working Hope this helps

                              Bram van Kampen

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

                              Relevance? :confused:

                              "One man's wage rise is another man's price increase." - Harold Wilson

                              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                              1 Reply Last reply
                              0
                              • L Lost User

                                ... and I don't think you meant to post this message to me.

                                B Offline
                                B Offline
                                Bram van Kampen
                                wrote on last edited by
                                #20

                                Sorry Richard, No I Did Not intend this for you. This topic became a Sort of a Labyrinth. The Original Person is evidently out of his/her depth! (S)he is still hammering the subject I see. I try to help, as we all do, but can get frustrated when good advise is ignored, as, I am sure you do to. Regards, Bram. :( ;) ;)

                                Bram van Kampen

                                1 Reply Last reply
                                0
                                • F ForNow

                                  Hi I have 3 rows of text in my rich edit. At the end of each line I move a carriage return line feed, to force a new line /r/n. Do these 2 bytes count as 2 characters when determining the count for the selection Thanks

                                  L Offline
                                  L Offline
                                  leon de boer
                                  wrote on last edited by
                                  #21

                                  EM_GETSELTEXT is explicit

                                  This message returns the number of characters copied, not including the terminating null character.

                                  The call is terminated by the null character and if you have CR,LF they will count as characters The return is a CHARACTER COUNT, if your edit box is unicode mode it still reflects the character NOT THE NUMBER OF BYTES. Hence when providing a buffer you are best to use an array of TCHAR rather than a standard byte array to allow for size difference. Also note when size a TCHAR array use _countof DO NOT use sizeof for the same reason. Standard unicode aware coding practice. Several of the comments have confusion between CHARACTER and BYTE within the meaning of the windows API. No such confusion exists.

                                  In vino veritas

                                  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