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. Moving Cursor position in Edit box !

Moving Cursor position in Edit box !

Scheduled Pinned Locked Moved C / C++ / MFC
game-devquestionhtmldatabasecom
5 Posts 4 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.
  • H Offline
    H Offline
    Hadi Rezaee
    wrote on last edited by
    #1

    How can i change the cursor position in a text box ? My month article: Game programming by DirectX by Lan Mader. Please visit in: www.geocities.com/hadi_rezaie/index.html Hadi Rezaie

    S B A 4 Replies Last reply
    0
    • H Hadi Rezaee

      How can i change the cursor position in a text box ? My month article: Game programming by DirectX by Lan Mader. Please visit in: www.geocities.com/hadi_rezaie/index.html Hadi Rezaie

      S Offline
      S Offline
      Stan Shannon
      wrote on last edited by
      #2

      I assume you mean the caret, not the cursor, and you want to do so programmatically. If so, the best way to do so is to sublcass the edit box which allows you to control the positioning of the caret. However, you should be aware that this is not a trivial undertaking as you need to be knowledgeable of text sizing issues. The caret itself can also be problamatic to deal with. "Any clod can have the facts, but having opinions is an art." Charles McCabe, San Francisco Chronicle

      1 Reply Last reply
      0
      • H Hadi Rezaee

        How can i change the cursor position in a text box ? My month article: Game programming by DirectX by Lan Mader. Please visit in: www.geocities.com/hadi_rezaie/index.html Hadi Rezaie

        S Offline
        S Offline
        Stan Shannon
        wrote on last edited by
        #3

        Actually, I need to correct myself. I checked and the CEdit api does have a PosFromChar method So you could do something like this...

        myedit.SetCaretPos( myedit.PosFromChar( index ));

        That was not there the last time I had to do the same thing. "Any clod can have the facts, but having opinions is an art." Charles McCabe, San Francisco Chronicle

        1 Reply Last reply
        0
        • H Hadi Rezaee

          How can i change the cursor position in a text box ? My month article: Game programming by DirectX by Lan Mader. Please visit in: www.geocities.com/hadi_rezaie/index.html Hadi Rezaie

          B Offline
          B Offline
          Brian Delahunty
          wrote on last edited by
          #4

          You can do it using the SetCaretPos() method. Regards, Brian Dela :-) "There should be an amendment to the constitution, that every president must be examined for paranoia before moving into office." - peterchen

          1 Reply Last reply
          0
          • H Hadi Rezaee

            How can i change the cursor position in a text box ? My month article: Game programming by DirectX by Lan Mader. Please visit in: www.geocities.com/hadi_rezaie/index.html Hadi Rezaie

            A Offline
            A Offline
            Andreas Masur
            wrote on last edited by
            #5

            void CEdit::SetSel(DWORD dwSelection, BOOL bNoScroll = FALSE);
            void CEdit::SetSel(int nStartChar, int nEndChar, BOOL bNoScroll = FALSE);

            To set the cursor at the end of the text within the control...

            // With associated member variable to the edit control and to the content
            UpdateData();
            m_EditControl.SetSel(m_EditContent.GetLength(), m_EditContent.GetLength());

            // With associated member variable to the content
            UpdateData();
            ((CEdit *) GetDlgItem(IDC_EDIT))->SetSel(m_EditContent.GetLength(), m_EditContent.GetLength());

            If you want to use the first function you have to set the starting position in the low-order word and and the ending position in the high-order word...thus

            // With associated member variable to the edit control and to the content
            UpdateData();

            // Set position
            DWORD dwSelection = m_EditContent.GetLength();
            dwSelection |= m_EditContent.GetLength() << 16;

            m_EditControl.SetSel(dwSelection);

            // With associated member variable to the content
            UpdateData();

            // Set position
            DWORD dwSelection = m_EditContent.GetLength();
            dwSelection |= m_EditContent.GetLength() << 16;

            ((CEdit *) GetDlgItem(IDC_EDIT))->SetSel(dwSelection);

            Ciao, Andreas "Software is like sex, it's better when it's free." - Linus Torvalds

            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