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. How to set caret position in Edit Control?

How to set caret position in Edit Control?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
4 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.
  • C Offline
    C Offline
    ClockDivider
    wrote on last edited by
    #1

    Hello and thanks for looking at my problem, I want to both select some text and set the caret postion in a edit control as if the user clicked the mouse at the end of the text and then draws the mouse pointer towards the beginning of the text. When doing so, the caret position is somewhere in the middle of the text and everything behind it is selected, like this: this is |some text where the bold stuff is selected and the caret is the "|". EM_SETSEL always results in selected text with the caret at its end, like this: this is some text| but I need the caret at the beginning. Does anyone know how to do? Thanks a lot... Martin Hoppe

    J A 2 Replies Last reply
    0
    • C ClockDivider

      Hello and thanks for looking at my problem, I want to both select some text and set the caret postion in a edit control as if the user clicked the mouse at the end of the text and then draws the mouse pointer towards the beginning of the text. When doing so, the caret position is somewhere in the middle of the text and everything behind it is selected, like this: this is |some text where the bold stuff is selected and the caret is the "|". EM_SETSEL always results in selected text with the caret at its end, like this: this is some text| but I need the caret at the beginning. Does anyone know how to do? Thanks a lot... Martin Hoppe

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

      Reverse the starting and ending position arguments: pCtrl->SendMessage( EM_SETSEL, // message to send (WPARAM) 10, // starting position (LPARAM) 5 // ending position (caret postion) ); INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

      C 1 Reply Last reply
      0
      • C ClockDivider

        Hello and thanks for looking at my problem, I want to both select some text and set the caret postion in a edit control as if the user clicked the mouse at the end of the text and then draws the mouse pointer towards the beginning of the text. When doing so, the caret position is somewhere in the middle of the text and everything behind it is selected, like this: this is |some text where the bold stuff is selected and the caret is the "|". EM_SETSEL always results in selected text with the caret at its end, like this: this is some text| but I need the caret at the beginning. Does anyone know how to do? Thanks a lot... Martin Hoppe

        A Offline
        A Offline
        Alexander M
        wrote on last edited by
        #3

        What about using EM_SETSEL with the beginning and the end at the same position? Don't try it, just do it! ;-)

        1 Reply Last reply
        0
        • J John R Shaw

          Reverse the starting and ending position arguments: pCtrl->SendMessage( EM_SETSEL, // message to send (WPARAM) 10, // starting position (LPARAM) 5 // ending position (caret postion) ); INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

          C Offline
          C Offline
          ClockDivider
          wrote on last edited by
          #4

          Thanks a lot for your answer, Andrew! Unfortunately I already tried that, but does NOT work. But maybe this is because I am on Embedded C++ 4.0? At least I am sure it does NOT work in Embedded C++ 4.0, but I will have a look in C++ 6.0 too. Do you or anyone have a solution for eMbedded C++, too?. Thank you very much... Martin

          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