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. Edit Control Problem

Edit Control Problem

Scheduled Pinned Locked Moved C / C++ / MFC
beta-testingjsonhelpquestioncode-review
18 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.
  • L Lost User

    I have just tried this (with VS 2010 Express) and it selects and highlights the text correctly. Can you show the exact code you are using? As a suggestion, do not use the A or W suffixes on Windows API calls. Use the base name, without the suffix, and let the compiler generate the correct call based on your projrct's Unicode/ASCII setting.

    P Offline
    P Offline
    programmingalholic
    wrote on last edited by
    #4

    I've tried to omit the suffix letter and it still produced the same effect. Below is code that sends the EM_SETSEL message to the Edit control.

    int selPos = (int)(pInitialFound - lpWStr1) + 1;
    int selEnd = selPos + (lstrlenW(lpWStr0));
    SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);

    Are there any suggestions to better correct that problem?

    L L V 3 Replies Last reply
    0
    • D David Crow

      programmingalholic wrote:

      ...to make it locates the searched text enter from the another Edit control.

      This is very unclear. Are you wanting to select text (EM_SETSEL), or get the text that is selected (EM_GETSEL)? These are two separate problems, requiring two separate messages.

      "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

      P Offline
      P Offline
      programmingalholic
      wrote on last edited by
      #5

      I want to select text in the Edit control and make it has visual effect that represents the highlight of selected text. But how does WM_SETSEL come? It was undefined in the edition of my Visual Studio. Any suggestion please??

      D L 2 Replies Last reply
      0
      • P programmingalholic

        I've tried to omit the suffix letter and it still produced the same effect. Below is code that sends the EM_SETSEL message to the Edit control.

        int selPos = (int)(pInitialFound - lpWStr1) + 1;
        int selEnd = selPos + (lstrlenW(lpWStr0));
        SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);

        Are there any suggestions to better correct that problem?

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

        programmingalholic wrote:

        I've tried to omit the suffix letter and it still produced the same effect.

        That's because the A or W is nothing to do with your problem. That is just a suggestion for better code writing, and you should fix it in all your programs. As to the actual problem, what are the values of selPos and selEnd when the code runs?

        P 1 Reply Last reply
        0
        • L Lost User

          programmingalholic wrote:

          I've tried to omit the suffix letter and it still produced the same effect.

          That's because the A or W is nothing to do with your problem. That is just a suggestion for better code writing, and you should fix it in all your programs. As to the actual problem, what are the values of selPos and selEnd when the code runs?

          P Offline
          P Offline
          programmingalholic
          wrote on last edited by
          #7

          The selPos is the value denotes the first character's position of the selected text and the selEnd is the value denotes the end character's position of the selected text. Did any VS.Community users have the same experience like me?

          D L 2 Replies Last reply
          0
          • P programmingalholic

            The selPos is the value denotes the first character's position of the selected text and the selEnd is the value denotes the end character's position of the selected text. Did any VS.Community users have the same experience like me?

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

            programmingalholic wrote:

            The selPos is the value denotes the first character's position of the selected text and the selEnd is the value denotes the end character's position of the selected text.

            Seriously? :rolleyes: Richard asked what their values were, not what purpose they served.

            "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
            • P programmingalholic

              I want to select text in the Edit control and make it has visual effect that represents the highlight of selected text. But how does WM_SETSEL come? It was undefined in the edition of my Visual Studio. Any suggestion please??

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

              programmingalholic wrote:

              But how does WM_SETSEL come?

              Do you mean how is it used?

              "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
              • P programmingalholic

                The selPos is the value denotes the first character's position of the selected text and the selEnd is the value denotes the end character's position of the selected text. Did any VS.Community users have the same experience like me?

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

                I know that. But have you actually used your debugger to check that they are both valid at the time of your SendMessage call? Is selPos >= 0, and selEnd > selPos && < editTextLen()?

                P 1 Reply Last reply
                0
                • P programmingalholic

                  I want to select text in the Edit control and make it has visual effect that represents the highlight of selected text. But how does WM_SETSEL come? It was undefined in the edition of my Visual Studio. Any suggestion please??

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

                  programmingalholic wrote:

                  WM_SETSEL

                  There is no such message.

                  1 Reply Last reply
                  0
                  • P programmingalholic

                    I've used SendMessageW API to direct an EM_SETSEL message to a designated Edit control to make it locates the searched text entered from the another Edit control. Why it doesn't provide visual feedback to reflect its current state? I used Spy++ to detect the EM_SETSEL message and the message was correctly listed in the message window. Can anyone give suggestion? My current development tool is MSVS Community 2015, project type is Win32 that merely uses A.P.I.

                    J Offline
                    J Offline
                    Jochen Arndt
                    wrote on last edited by
                    #12

                    The default behaviour of edit controls is showing the selection only when the control has the focus. From your description I assume that another control (the search input field or a button) has the focus when you try to set the selection. But there is an option to show the selection even when the edit control does not have the focus: ES_NOHIDESEL[^]. Unfortunately the style can't be changed once the control exists. You have to set it when creating the edit control. If it is defined as static resource, set the option there (e.g. using the resource editor). For dynamically created edit controls pass the flag in the style parameter when calling CreateWindow or CreateWindowEx.

                    P 1 Reply Last reply
                    0
                    • P programmingalholic

                      I've tried to omit the suffix letter and it still produced the same effect. Below is code that sends the EM_SETSEL message to the Edit control.

                      int selPos = (int)(pInitialFound - lpWStr1) + 1;
                      int selEnd = selPos + (lstrlenW(lpWStr0));
                      SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);

                      Are there any suggestions to better correct that problem?

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

                      As per Richard said debug the dam thing because there is something wrong with a value and you are asking us to guess what. However something obvious to me which you have not explained you have two different string pointers in the above lpWStr1 and lpWstr0 and since there is something wrong with selPos or selEnd which you haven't debugged is this related as no explaination of these???

                      In vino veritas

                      1 Reply Last reply
                      0
                      • P programmingalholic

                        I've tried to omit the suffix letter and it still produced the same effect. Below is code that sends the EM_SETSEL message to the Edit control.

                        int selPos = (int)(pInitialFound - lpWStr1) + 1;
                        int selEnd = selPos + (lstrlenW(lpWStr0));
                        SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);

                        Are there any suggestions to better correct that problem?

                        V Offline
                        V Offline
                        Victor Nijegorodov
                        wrote on last edited by
                        #14

                        programmingalholic wrote:

                        Below is code that sends the EM_SETSEL message to the Edit control.

                        int selPos = (int)(pInitialFound - lpWStr1) + 1;
                        int selEnd = selPos + (lstrlenW(lpWStr0));
                        SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);

                        And what are the actual values of selPos, selEnd, and the length of the text in hwndEdit edit control?

                        L P 2 Replies Last reply
                        0
                        • V Victor Nijegorodov

                          programmingalholic wrote:

                          Below is code that sends the EM_SETSEL message to the Edit control.

                          int selPos = (int)(pInitialFound - lpWStr1) + 1;
                          int selEnd = selPos + (lstrlenW(lpWStr0));
                          SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);

                          And what are the actual values of selPos, selEnd, and the length of the text in hwndEdit edit control?

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

                          See Re: Edit Control Problem - C / C++ / MFC Discussion Boards - CodeProject[^] and OP's reply.

                          1 Reply Last reply
                          0
                          • J Jochen Arndt

                            The default behaviour of edit controls is showing the selection only when the control has the focus. From your description I assume that another control (the search input field or a button) has the focus when you try to set the selection. But there is an option to show the selection even when the edit control does not have the focus: ES_NOHIDESEL[^]. Unfortunately the style can't be changed once the control exists. You have to set it when creating the edit control. If it is defined as static resource, set the option there (e.g. using the resource editor). For dynamically created edit controls pass the flag in the style parameter when calling CreateWindow or CreateWindowEx.

                            P Offline
                            P Offline
                            programmingalholic
                            wrote on last edited by
                            #16

                            That's 100% right !! It had to do with ES_NOHIDESEL style, I had succeeded tap into it. However, thanks to all members of this community that had posed attention to my problem. :-D

                            1 Reply Last reply
                            0
                            • V Victor Nijegorodov

                              programmingalholic wrote:

                              Below is code that sends the EM_SETSEL message to the Edit control.

                              int selPos = (int)(pInitialFound - lpWStr1) + 1;
                              int selEnd = selPos + (lstrlenW(lpWStr0));
                              SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);

                              And what are the actual values of selPos, selEnd, and the length of the text in hwndEdit edit control?

                              P Offline
                              P Offline
                              programmingalholic
                              wrote on last edited by
                              #17

                              the actual value of selPos and selEnd just represent as what they are, both contained int value that denoted character index. To hwndEdit, the return value of GetWindowTextLengthW just not false ( other values than 0 ).

                              1 Reply Last reply
                              0
                              • L Lost User

                                I know that. But have you actually used your debugger to check that they are both valid at the time of your SendMessage call? Is selPos >= 0, and selEnd > selPos && < editTextLen()?

                                P Offline
                                P Offline
                                programmingalholic
                                wrote on last edited by
                                #18

                                The selPos and selEnd had actually referred to the precise character index of the selected text. Thanks.

                                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