How can I set the focus to an specific item?
-
:) I have just asked a question the day before yesterday, And thanks to Alok and Jörgen Sigvardsson who gave me nice ways to solve my last question. Now I have got a new question to ask. Can I set the keyboard focus on a radio button when the dialog pop up? I use GetDlgItem(IDC_RADIO1)->SetFocus(); in the OnInitDialog(). But it didn't work. //IDC_RADIO1 is the ID of the radio button in the dialog //where I wish the keyboard focus to stay at when the dialog pop up Thanks!
-
:) I have just asked a question the day before yesterday, And thanks to Alok and Jörgen Sigvardsson who gave me nice ways to solve my last question. Now I have got a new question to ask. Can I set the keyboard focus on a radio button when the dialog pop up? I use GetDlgItem(IDC_RADIO1)->SetFocus(); in the OnInitDialog(). But it didn't work. //IDC_RADIO1 is the ID of the radio button in the dialog //where I wish the keyboard focus to stay at when the dialog pop up Thanks!
If you set the focus in
OnInitDialog()
, you must returnFALSE
fromOnInitDialog()
. If you don't, the normal Windows dialog handling will set the focus to the first control in the tab order.
Software Zen:
delete this;
-
If you set the focus in
OnInitDialog()
, you must returnFALSE
fromOnInitDialog()
. If you don't, the normal Windows dialog handling will set the focus to the first control in the tab order.
Software Zen:
delete this;
Thanks! I tried the method you told me, And it did work in the dialog. But when I tried this in a fromview, which contains the item I want to set the keyboard focus at, it didn't work. Because the OnInitialUpdate() function in the CFormView class doesn't have a return value. What can I do in this case? Thanks!
-
Thanks! I tried the method you told me, And it did work in the dialog. But when I tried this in a fromview, which contains the item I want to set the keyboard focus at, it didn't work. Because the OnInitialUpdate() function in the CFormView class doesn't have a return value. What can I do in this case? Thanks!
You could try to post your form view a special message, that once recieved, will set the focus for you, after the formview has initialized. Once you are out of an 'init' handler, like OnInitDialog it is easy to set the focus to any control you want. The default handlers almost always try to set one for you, which as you have discovered is not always convenient.