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. focus in edit control

focus in edit control

Scheduled Pinned Locked Moved C / C++ / MFC
help
11 Posts 5 Posters 2 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.
  • B Offline
    B Offline
    bhogavalli suresh
    wrote on last edited by
    #1

    i am using dialog ,in that i have an edit control,when ever my dialog displays cursor must be in the edit control,plz help me............

    N S W 4 Replies Last reply
    0
    • B bhogavalli suresh

      i am using dialog ,in that i have an edit control,when ever my dialog displays cursor must be in the edit control,plz help me............

      N Offline
      N Offline
      Nishad S
      wrote on last edited by
      #2

      You can call GotoDlgCtrl() API for that edit to set the focus. If it is in OnInitDialog, you should return FALSE.

      - NS -

      B 1 Reply Last reply
      0
      • N Nishad S

        You can call GotoDlgCtrl() API for that edit to set the focus. If it is in OnInitDialog, you should return FALSE.

        - NS -

        B Offline
        B Offline
        bhogavalli suresh
        wrote on last edited by
        #3

        ok fine,if it in another function ,wts the processs............

        N 1 Reply Last reply
        0
        • B bhogavalli suresh

          ok fine,if it in another function ,wts the processs............

          N Offline
          N Offline
          Nishad S
          wrote on last edited by
          #4

          GotoDlgCtrl itself... :)

          - NS -

          W 1 Reply Last reply
          0
          • B bhogavalli suresh

            i am using dialog ,in that i have an edit control,when ever my dialog displays cursor must be in the edit control,plz help me............

            S Offline
            S Offline
            Sreedhar DV
            wrote on last edited by
            #5

            Set the "Tab stop" for the edit control as 1. For doing this click Ctrl+D on the resource view of the dialog. Set the edit control tab stop as 1. It is the simplest way to solve your problem.:)

            Sreedhar DV

            1 Reply Last reply
            0
            • B bhogavalli suresh

              i am using dialog ,in that i have an edit control,when ever my dialog displays cursor must be in the edit control,plz help me............

              W Offline
              W Offline
              Wamuti
              wrote on last edited by
              #6

              add a member variable for that edit box e.g. "m_deEditBox" using the class wizard and set the category as a control and the variable type should change to be automaticaly CEdit. Wherever you want to receive focus use the SetFocus() and that should do the trick e.g. : m_deEditBox.SetFocus(); Only make sure m_deEditBox is visible within the class you are using! :)

              Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.

              S 1 Reply Last reply
              0
              • N Nishad S

                GotoDlgCtrl itself... :)

                - NS -

                W Offline
                W Offline
                Wamuti
                wrote on last edited by
                #7

                tried setting it to a member of CEdit(The edit box itself ) but GoToDlgCtrl is not a member of CEdit.

                Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.

                N 1 Reply Last reply
                0
                • W Wamuti

                  add a member variable for that edit box e.g. "m_deEditBox" using the class wizard and set the category as a control and the variable type should change to be automaticaly CEdit. Wherever you want to receive focus use the SetFocus() and that should do the trick e.g. : m_deEditBox.SetFocus(); Only make sure m_deEditBox is visible within the class you are using! :)

                  Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.

                  S Offline
                  S Offline
                  Stephen Hewitt
                  wrote on last edited by
                  #8

                  Calling SetFocus to set the focus to a control on a dialog box is wrong! See here[^] for details.

                  Steve

                  W 1 Reply Last reply
                  0
                  • W Wamuti

                    tried setting it to a member of CEdit(The edit box itself ) but GoToDlgCtrl is not a member of CEdit.

                    Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.

                    N Offline
                    N Offline
                    Nishad S
                    wrote on last edited by
                    #9

                    Wamuti wrote:

                    tried setting it to a member of CEdit(The edit box itself )

                    No... You have to call like, GotoDlgCtrl( &m_edit );

                    - NS -

                    1 Reply Last reply
                    0
                    • S Stephen Hewitt

                      Calling SetFocus to set the focus to a control on a dialog box is wrong! See here[^] for details.

                      Steve

                      W Offline
                      W Offline
                      Wamuti
                      wrote on last edited by
                      #10

                      First, Thanks for the correction. Second, sorry this is long but here goes; When i tested SetFocus(), i placed it in two buttons as: void CSetfocusDlg::OnBfirst() //first button { // TODO: Add your control notification handler code here m_deOne.SetFocus(); } void CSetfocusDlg::OnBsecond() //second button { // TODO: Add your control notification handler code here m_deTwo.SetFocus(); } and it worked just fine. But if i am getting it right, if there is a button in a dialog, SetFocus() is reserved for the default push button, right? This means that even if i put m_editControl.SetFocus() in OnInitDialog(), i would still not get the desired effect of setting the cursor to the Edit control(what i understand from the site you directed me and practically i have tried, so i was very wrong indeed). Ofcourse it makes sense to use the WM_NEXTDLGCTL but i cant get the message in the class wizard. Then how do i code the handler? Please help!:sigh:

                      Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.

                      1 Reply Last reply
                      0
                      • B bhogavalli suresh

                        i am using dialog ,in that i have an edit control,when ever my dialog displays cursor must be in the edit control,plz help me............

                        W Offline
                        W Offline
                        Wamuti
                        wrote on last edited by
                        #11

                        Oops:doh: sorry, using SetFocus() won't work. But i am learning. Thanks for understanding.

                        Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.

                        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