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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SetCursor position

SetCursor position

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

    Hi all, I am trying to set the cursor for edit box to the next line: Here is the code i am trying,

    CEdit m_TestCtrl;
    CString m_Test1;
    void CTest::OnChangeEditTest()
    {
    CString str,str1;
    UpdateData(TRUE);
    str1 = m_Test1; // reading the value from edit box
    str1 += ":"; // Appending the value with ":"
    int nLength = m_TestCtrl.GetWindowTextLength(); //trying to get the Length of Text from EditControl
    m_TestCtrl.SetSel(nLength ); //trying to set the cursor after the character ":"
    m_Test1 = str1; // Passing the appended value to edit Box
    UpdateData(FALSE);
    }

    It is appending,but the cursor is going to the first position.
    Can anyone tell me where i am going wrong

    Thank you Manju

    D 1 Reply Last reply
    0
    • M manju 3

      Hi all, I am trying to set the cursor for edit box to the next line: Here is the code i am trying,

      CEdit m_TestCtrl;
      CString m_Test1;
      void CTest::OnChangeEditTest()
      {
      CString str,str1;
      UpdateData(TRUE);
      str1 = m_Test1; // reading the value from edit box
      str1 += ":"; // Appending the value with ":"
      int nLength = m_TestCtrl.GetWindowTextLength(); //trying to get the Length of Text from EditControl
      m_TestCtrl.SetSel(nLength ); //trying to set the cursor after the character ":"
      m_Test1 = str1; // Passing the appended value to edit Box
      UpdateData(FALSE);
      }

      It is appending,but the cursor is going to the first position.
      Can anyone tell me where i am going wrong

      Thank you Manju

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

      manju 3 wrote:

      It is appending,but the cursor is going to the first position.

      You need to send the edit control an EM_SETSEL message.

      manju 3 wrote:

      Can anyone tell me where i am going wrong

      My first course of action would be to get rid of the calls to UpdateData(). Use GetWindowText() and SetWindowText() instead.

      "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

      "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

      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