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 the position of the blinking text cursor in a CEdit box.

How to set the position of the blinking text cursor in a CEdit box.

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelpc++tutorial
8 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.
  • W Offline
    W Offline
    whatever whatever com
    wrote on last edited by
    #1

    Hi, I am doing some GUI dialogs in MFC. The problem goes like this: I have a parent dialog which can create a modeless child "keyboard" dialog,with some special prescribed keys. The user is suppose to click on keys on the "keyboard" dialog and the input is suppose to appear on an Edit box on the parent dialog. The issue is that I want the user to have the freedom of using both the physical keyboard and the "Keyboard" dialog. So, I tried to use SetFocus() onto the Parent's Edit box after hitting keys on the "Keyboard" dialog. The problem is that the after SetFocus() is issued, the blinking text cursor is always at the beginng left end of the Edit box regardless of whether there is any text in the edit box. This poses a problem when the user changes to using the physical keyboard since text will be input at the beginning of the current text rather than from the end of the text in the Edit box. So my question is how do I set the position of the blinking text cursor to the end of the text after SetFocus()? Thanks alot! :-D

    P R J 3 Replies Last reply
    0
    • W whatever whatever com

      Hi, I am doing some GUI dialogs in MFC. The problem goes like this: I have a parent dialog which can create a modeless child "keyboard" dialog,with some special prescribed keys. The user is suppose to click on keys on the "keyboard" dialog and the input is suppose to appear on an Edit box on the parent dialog. The issue is that I want the user to have the freedom of using both the physical keyboard and the "Keyboard" dialog. So, I tried to use SetFocus() onto the Parent's Edit box after hitting keys on the "Keyboard" dialog. The problem is that the after SetFocus() is issued, the blinking text cursor is always at the beginng left end of the Edit box regardless of whether there is any text in the edit box. This poses a problem when the user changes to using the physical keyboard since text will be input at the beginning of the current text rather than from the end of the text in the Edit box. So my question is how do I set the position of the blinking text cursor to the end of the text after SetFocus()? Thanks alot! :-D

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      What about CWnd::SetCaretPos ?

      Prasad Notifier using ATL | Operator new[],delete[][^]

      J W 2 Replies Last reply
      0
      • W whatever whatever com

        Hi, I am doing some GUI dialogs in MFC. The problem goes like this: I have a parent dialog which can create a modeless child "keyboard" dialog,with some special prescribed keys. The user is suppose to click on keys on the "keyboard" dialog and the input is suppose to appear on an Edit box on the parent dialog. The issue is that I want the user to have the freedom of using both the physical keyboard and the "Keyboard" dialog. So, I tried to use SetFocus() onto the Parent's Edit box after hitting keys on the "Keyboard" dialog. The problem is that the after SetFocus() is issued, the blinking text cursor is always at the beginng left end of the Edit box regardless of whether there is any text in the edit box. This poses a problem when the user changes to using the physical keyboard since text will be input at the beginning of the current text rather than from the end of the text in the Edit box. So my question is how do I set the position of the blinking text cursor to the end of the text after SetFocus()? Thanks alot! :-D

        R Offline
        R Offline
        Rajasekharan Vengalil
        wrote on last edited by
        #3

        You could do this:

        CEdit *pEdit = static_cast<CEdit *>( GetDlgItem( IDC_THE_EDIT_BOX ) );
        int iLength = pEdit->GetWindowTextLength();
        pEdit->SetSel( iLength, iLength );

        -- gleat http://blogorama.nerdworks.in[^] --

        W 1 Reply Last reply
        0
        • P prasad_som

          What about CWnd::SetCaretPos ?

          Prasad Notifier using ATL | Operator new[],delete[][^]

          J Offline
          J Offline
          James R Twine
          wrote on last edited by
          #4

          That may cause a visual indication, but the underlying edit control will maintain its last insertion point.    Peace!

          -=- James
          Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
          Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
          See DeleteFXPFiles

          1 Reply Last reply
          0
          • W whatever whatever com

            Hi, I am doing some GUI dialogs in MFC. The problem goes like this: I have a parent dialog which can create a modeless child "keyboard" dialog,with some special prescribed keys. The user is suppose to click on keys on the "keyboard" dialog and the input is suppose to appear on an Edit box on the parent dialog. The issue is that I want the user to have the freedom of using both the physical keyboard and the "Keyboard" dialog. So, I tried to use SetFocus() onto the Parent's Edit box after hitting keys on the "Keyboard" dialog. The problem is that the after SetFocus() is issued, the blinking text cursor is always at the beginng left end of the Edit box regardless of whether there is any text in the edit box. This poses a problem when the user changes to using the physical keyboard since text will be input at the beginning of the current text rather than from the end of the text in the Edit box. So my question is how do I set the position of the blinking text cursor to the end of the text after SetFocus()? Thanks alot! :-D

            J Offline
            J Offline
            James R Twine
            wrote on last edited by
            #5

            The SetSel(...) solution is the best, IMHO, although I question the habit of casting the return of CWnd::GetDlgItem(...) unless you really know what you are doing...    You should investigate the MA_NOACTIVATE return value from processing the WM_MOUSEACTIVATE message.  I believe that is how you can get an on-screen keyboard to not cause kill focus events to be sent to another window when it is is being used.  You may have to rely on mouse position as opposed to button click events if you do this.    Peace!

            -=- James
            Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
            Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            See DeleteFXPFiles

            W 1 Reply Last reply
            0
            • R Rajasekharan Vengalil

              You could do this:

              CEdit *pEdit = static_cast<CEdit *>( GetDlgItem( IDC_THE_EDIT_BOX ) );
              int iLength = pEdit->GetWindowTextLength();
              pEdit->SetSel( iLength, iLength );

              -- gleat http://blogorama.nerdworks.in[^] --

              W Offline
              W Offline
              whatever whatever com
              wrote on last edited by
              #6

              This is indeed a great method! works nice n sweet. Thanks.:-D

              1 Reply Last reply
              0
              • P prasad_som

                What about CWnd::SetCaretPos ?

                Prasad Notifier using ATL | Operator new[],delete[][^]

                W Offline
                W Offline
                whatever whatever com
                wrote on last edited by
                #7

                Thanks for the sugestion. At least I now know that blinking cursor is called a caret. :laugh:

                1 Reply Last reply
                0
                • J James R Twine

                  The SetSel(...) solution is the best, IMHO, although I question the habit of casting the return of CWnd::GetDlgItem(...) unless you really know what you are doing...    You should investigate the MA_NOACTIVATE return value from processing the WM_MOUSEACTIVATE message.  I believe that is how you can get an on-screen keyboard to not cause kill focus events to be sent to another window when it is is being used.  You may have to rely on mouse position as opposed to button click events if you do this.    Peace!

                  -=- James
                  Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                  Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                  See DeleteFXPFiles

                  W Offline
                  W Offline
                  whatever whatever com
                  wrote on last edited by
                  #8

                  Thanks for your input. the SetSel method has worked well for me. Dint investigate the WM_MOUSEACTIVATE method as using mouse position may complicated matters for me. anyway, 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