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. SetFocus for a chosen Edit Control in MFC

SetFocus for a chosen Edit Control in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcsharptutorialquestion
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.
  • R Offline
    R Offline
    robert_s
    wrote on last edited by
    #1

    Hi. I am writing an application where I have a dialog with one combo box and 4 edit controls. Now when I open that dialog there is always first edit control focused. How can change this behaviour so for example rather than the first I would like the third edit control to be automatically focused, so when the user opens the dialog one can start typing into that (third) edit control rather than using a mouse to click on it first. I thought it would be as simple as that: BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); CtrlSourceExt.SetFocus(); // PROBLEM IS HERE - Set foucus to this edit control (this Doesn't work) (NOTE: variable CtrlSourceExt is of type CEdit) UpdateData(); return TRUE; // return TRUE unless you set the focus to a control } Actually I remember in VC++ 6 I could specify the order of things to be focused in resource editor when designing a dialog. So if I had say 4 edit controls I could set focus in this order 4,2,1,3 so the first hightlighed edit control would be 4 then if the user pressed tab once it would take him to edit control 2 then 1 and 3. But now in VC++ 2003 .NET it doesnt work. Same thing with profiler I just cant find it. I dont know why they got rid of such useful thing. Anyway going back to the subject. Can anybody help? Thanks.

    K T R 3 Replies Last reply
    0
    • R robert_s

      Hi. I am writing an application where I have a dialog with one combo box and 4 edit controls. Now when I open that dialog there is always first edit control focused. How can change this behaviour so for example rather than the first I would like the third edit control to be automatically focused, so when the user opens the dialog one can start typing into that (third) edit control rather than using a mouse to click on it first. I thought it would be as simple as that: BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); CtrlSourceExt.SetFocus(); // PROBLEM IS HERE - Set foucus to this edit control (this Doesn't work) (NOTE: variable CtrlSourceExt is of type CEdit) UpdateData(); return TRUE; // return TRUE unless you set the focus to a control } Actually I remember in VC++ 6 I could specify the order of things to be focused in resource editor when designing a dialog. So if I had say 4 edit controls I could set focus in this order 4,2,1,3 so the first hightlighed edit control would be 4 then if the user pressed tab once it would take him to edit control 2 then 1 and 3. But now in VC++ 2003 .NET it doesnt work. Same thing with profiler I just cant find it. I dont know why they got rid of such useful thing. Anyway going back to the subject. Can anybody help? Thanks.

      K Offline
      K Offline
      KalliMan
      wrote on last edited by
      #2

      Perhaps u must set the focus in 'CTestDlg::OnShowWindow()'. KalliMan

      1 Reply Last reply
      0
      • R robert_s

        Hi. I am writing an application where I have a dialog with one combo box and 4 edit controls. Now when I open that dialog there is always first edit control focused. How can change this behaviour so for example rather than the first I would like the third edit control to be automatically focused, so when the user opens the dialog one can start typing into that (third) edit control rather than using a mouse to click on it first. I thought it would be as simple as that: BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); CtrlSourceExt.SetFocus(); // PROBLEM IS HERE - Set foucus to this edit control (this Doesn't work) (NOTE: variable CtrlSourceExt is of type CEdit) UpdateData(); return TRUE; // return TRUE unless you set the focus to a control } Actually I remember in VC++ 6 I could specify the order of things to be focused in resource editor when designing a dialog. So if I had say 4 edit controls I could set focus in this order 4,2,1,3 so the first hightlighed edit control would be 4 then if the user pressed tab once it would take him to edit control 2 then 1 and 3. But now in VC++ 2003 .NET it doesnt work. Same thing with profiler I just cant find it. I dont know why they got rid of such useful thing. Anyway going back to the subject. Can anybody help? Thanks.

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

        robert_s wrote: return TRUE; // return TRUE unless you set the focus to a control


        TOXCCT >>> GEII power

        1 Reply Last reply
        0
        • R robert_s

          Hi. I am writing an application where I have a dialog with one combo box and 4 edit controls. Now when I open that dialog there is always first edit control focused. How can change this behaviour so for example rather than the first I would like the third edit control to be automatically focused, so when the user opens the dialog one can start typing into that (third) edit control rather than using a mouse to click on it first. I thought it would be as simple as that: BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); CtrlSourceExt.SetFocus(); // PROBLEM IS HERE - Set foucus to this edit control (this Doesn't work) (NOTE: variable CtrlSourceExt is of type CEdit) UpdateData(); return TRUE; // return TRUE unless you set the focus to a control } Actually I remember in VC++ 6 I could specify the order of things to be focused in resource editor when designing a dialog. So if I had say 4 edit controls I could set focus in this order 4,2,1,3 so the first hightlighed edit control would be 4 then if the user pressed tab once it would take him to edit control 2 then 1 and 3. But now in VC++ 2003 .NET it doesnt work. Same thing with profiler I just cant find it. I dont know why they got rid of such useful thing. Anyway going back to the subject. Can anybody help? Thanks.

          R Offline
          R Offline
          robert_s
          wrote on last edited by
          #4

          Thanks toxcct :o) Returning FALSE fixes the problem :) HAHA!!! S*** I haven't noticed these comments generated by a wizard. How embarassing.... Sorry! But still its a bit silly to me to return FALSE. The function name (OnInitiDialog) suggests that I am initializing a dialog and if successfully initialized it should return TRUE otherwise FALSE if unsuccessful. But here even though the dialog is initialized I am returning FALSE. hehe! I cant see any logic here? Perhaps I still need to learn more the way how MS people think :o) hehe.. Thanks all for help!!

          D 1 Reply Last reply
          0
          • R robert_s

            Thanks toxcct :o) Returning FALSE fixes the problem :) HAHA!!! S*** I haven't noticed these comments generated by a wizard. How embarassing.... Sorry! But still its a bit silly to me to return FALSE. The function name (OnInitiDialog) suggests that I am initializing a dialog and if successfully initialized it should return TRUE otherwise FALSE if unsuccessful. But here even though the dialog is initialized I am returning FALSE. hehe! I cant see any logic here? Perhaps I still need to learn more the way how MS people think :o) hehe.. Thanks all for help!!

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

            robert_s wrote: But still its a bit silly to me to return FALSE. The function name (OnInitiDialog) suggests that I am initializing a dialog... The return value has nothing to with success/failure. It simply denotes whether the application has set the input focus to one of the controls in the dialog box.


            "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

            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