CButton SetFocus
-
Hi, I want to set the focus to a CButton control. I'm using
GetDlgItem(IDC_MY_BUTTON)->SetFocus();
but it does not work. It works for CEdit controls but not CButtons. How can I set the focus to a CButton control? -
Hi, I want to set the focus to a CButton control. I'm using
GetDlgItem(IDC_MY_BUTTON)->SetFocus();
but it does not work. It works for CEdit controls but not CButtons. How can I set the focus to a CButton control?AORD wrote:
GetDlgItem(IDC_MY_BUTTON)->SetFocus();
Well, it wont work. I have been facing similar problems, and I go down to
PostMessage()
level. What you probably can do is, Get the handle of the button with which you would want to deal, and then continue by posting an appropriate message. The following code snippet should help solving your problem.HWND hButton; GetDlgItem(ID_MYBUTTON, &hButton); ::PostMessage(hButton, BN_SETFOCUS, 1, 0);
Regards, Rajesh R. Subramanian, Cyberscape Multimeida Limited, Bombay, India. You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each. -
Hi, I want to set the focus to a CButton control. I'm using
GetDlgItem(IDC_MY_BUTTON)->SetFocus();
but it does not work. It works for CEdit controls but not CButtons. How can I set the focus to a CButton control?toxcct is right. The button gets actually the focus. You can prove that to yourself by pressing the "space" key after you set the control to that button. You will see how it goes down and up. SkyWalker
-
Hi, I want to set the focus to a CButton control. I'm using
GetDlgItem(IDC_MY_BUTTON)->SetFocus();
but it does not work. It works for CEdit controls but not CButtons. How can I set the focus to a CButton control?... and to see the difference, add
PostMessage(WM_KEYDOWN, (WPARAM)VK_TAB);
inOnInitDialog()
This will start showing you the focus rectangle on your buttons. SkyWalker -
AORD wrote:
GetDlgItem(IDC_MY_BUTTON)->SetFocus();
Well, it wont work. I have been facing similar problems, and I go down to
PostMessage()
level. What you probably can do is, Get the handle of the button with which you would want to deal, and then continue by posting an appropriate message. The following code snippet should help solving your problem.HWND hButton; GetDlgItem(ID_MYBUTTON, &hButton); ::PostMessage(hButton, BN_SETFOCUS, 1, 0);
Regards, Rajesh R. Subramanian, Cyberscape Multimeida Limited, Bombay, India. You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.See my answers down ... SkyWalker -- modified at 11:46 Monday 14th November, 2005
-
... and to see the difference, add
PostMessage(WM_KEYDOWN, (WPARAM)VK_TAB);
inOnInitDialog()
This will start showing you the focus rectangle on your buttons. SkyWalkerIt is not during InitDialog(), It is that he wants the button to achieve focus during run time. The fact is that It acquires focus but still is not clearly visble. My solution works, I hope. You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.
-
It is not during InitDialog(), It is that he wants the button to achieve focus during run time. The fact is that It acquires focus but still is not clearly visble. My solution works, I hope. You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.
Rajesh R. Subramanian wrote:
It is not during InitDialog(),
Correct. I want the user to press enter while the focus is on an CEdit control, then I want the focus to move to a CButton control. But the CButton control does not obtain its normal focus (as it would if the user had pressed the tab key). Yes toxcct & Mircea you are correct, the CButton does obtain a sort of focus by using
GetDlgItem(IDC_MY_BUTTON)->SetFocus();
and the button is drawn incorrectly and nothing happens when the enter key is pressed (the space key works).::PostMessage(hButton, BN_SETFOCUS, 1, 0);
This works the same asGetDlgItem(IDC_MY_BUTTON)->SetFocus();
.PostMessage(WM_KEYDOWN, (WPARAM)VK_TAB);
This strange because it moves the focus backwards, that is the focus does not follow the Layout Tab order, :omg: thats not expected. So I have changed the Tab order and now it works, but this is at odds with the tab order the user would expect :(. Thanks for the help :):):), It's not quite right, but is close. -
actually, yes, it set the focus, but the problem is graphical (button style pb). but i'd ask you one more thing : do you want to set the focus on the button, or change the default button ??
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
You are correct, it does have focus, but does not accept the enter key. I want to set the focus. See the replys below Many Thanks, AORD
hum, it seems that what you need have been answered several ways, but at a low level... did you try
CWnd::GetDefID()
? by using this function, the window the button is on will change its default button (it will remove the property from the last one to set it to the button you provide then). this way, you'll be able to press the "enter" key to use you button.
TOXCCT >>> GEII power
[toxcct][VisualCalc]