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. Repositioning a cursor in a control

Repositioning a cursor in a control

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

    I'm changing the text in a control and I want to reposition the cursor at the end of the text after I display the text. What I'm doing doesn't work! The cursor is always set to the beginging of the text (due to the "SetFocus"). Any ideas? NB: m_CheckNoCtrl is a control to the field! m_CheckNoCtrl.SetWindowText(szTemp); // Paint new text in control m_CheckNoCtrl.SetFocus(); // Set focus to control int ndx = m_CheckNo.GetLength(); // Get the new length SendMessage (EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx);

    F 1 Reply Last reply
    0
    • T Tombo

      I'm changing the text in a control and I want to reposition the cursor at the end of the text after I display the text. What I'm doing doesn't work! The cursor is always set to the beginging of the text (due to the "SetFocus"). Any ideas? NB: m_CheckNoCtrl is a control to the field! m_CheckNoCtrl.SetWindowText(szTemp); // Paint new text in control m_CheckNoCtrl.SetFocus(); // Set focus to control int ndx = m_CheckNo.GetLength(); // Get the new length SendMessage (EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx);

      F Offline
      F Offline
      FarPointer
      wrote on last edited by
      #2

      Hi, for me it works CString sJaya("HELLOPSODPO"); c_numedit.SetWindowText(sJaya); // Paint new text in control c_numedit.SetFocus(); // Set focus to control int ndx = sJaya.GetLength (); c_numedit.SendMessage (EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx); And i see that you are setting with one text and doing a getLength() on another wats that for . Regards, FarPointer -- modified at 11:50 Wednesday 18th January, 2006

      T 1 Reply Last reply
      0
      • F FarPointer

        Hi, for me it works CString sJaya("HELLOPSODPO"); c_numedit.SetWindowText(sJaya); // Paint new text in control c_numedit.SetFocus(); // Set focus to control int ndx = sJaya.GetLength (); c_numedit.SendMessage (EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx); And i see that you are setting with one text and doing a getLength() on another wats that for . Regards, FarPointer -- modified at 11:50 Wednesday 18th January, 2006

        T Offline
        T Offline
        Tombo
        wrote on last edited by
        #3

        The GetLength()is on the variable I set up for the text. However you solve my problem! I changed the SendMessage (EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx); To: m_CheckNoCtrl.SendMessage (EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx); I overlooked specifing the control I was sending the message for! It now works for me too. 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