|
-
October 17th, 2003, 08:52 PM
#1
A funny thing happened on the way to setting focus
I have encountered a strange phenomenon where i intend to switch the focus from the OK button to a button with an ID of IDC_NEXTPAGE.
What, in fact happens, is that the focus is shifted to the SPACE BAR instead of the ENTER key ?? Whoaa! How can this be?
the code:
..stuff
UpdateData()
.
.
m_ScanOK.EnableWindow(FALSE);
m_ScanNxtPg.EnableWindow(TRUE);
CWnd* pNP= GetDlgItem(IDC_NEXTPAGE);
pNP->SetFocus();
.
.
kin u figger it?
--------------------------------------------
http://www.volfirst.net/~sirjorj/index.html
---------------------------------------------
-
October 18th, 2003, 05:13 AM
#2
The "focus" refers to the control that will receive key presses. When you press TAB the focus moves from control to control.
What you describe is normal. When you press the spacebar the control that has the "focus" receives the key. For a button, pressing the spacebar presses the button. The Enter key always corresponds to pressing the DEFAULT button (one that has the BS_DEFPUSHBUTTON style - usually the OK BUtton). This style means that the button will be pressed when you press ENTER whether it has the focus or not. Only one control in a dialog should have the BS_DEFPUSHBUTTON style.
Hope that answers your question.
Dave Mclelland.
-
October 18th, 2003, 10:09 AM
#3
[QUOTE]Originally posted by Dave McLelland
.... The Enter key always corresponds to pressing the DEFAULT button (one that has the BS_DEFPUSHBUTTON style - usually the OK BUtton). This style means that the button will be pressed when you press ENTER whether it has the focus or not. .../QUOTE]
If i understand you, my SetFocus is OK but (for some unknown reason) the BS_DEFPUSHBUTTON style has gotten switched from
OK Button to what? - SPACEBAR??
The question remains: How to get input to respond to the ENTER key instead of SPACEBAR? If it means setting BS_DEFPUSHBUTTON to OK button, how is that done?
Tnx
--------------------------------------------
http://www.volfirst.net/~sirjorj/index.html
---------------------------------------------
-
October 18th, 2003, 04:45 PM
#4
To make a button respond to Enter use the ModifyStyle function.
Remove the BS_DEFPUSHBUTTON style from the current default button then set it on your target button.
If you want a button to always be the default (ie. you want it pressed when you press enter), set the style in the dialog editor.
I am not sure that you understand the focus. The focus passes from control to control as you press the tab key. All the focus means is that keyboard input is offered to the control with the focus. Think of the focus as the window to which the keyboard is talking.
When you press enter on a dialog box, the button which has the BS_DEFPUSHBUTTON style gets pressed regardless of which control actually has the focus. When a button has the focus, pressing the spacebar is equivalent to pushing the button.
Dave Mclelland.
-
October 18th, 2003, 10:49 PM
#5
OK Dave-
I now understand better what 'focus' is.
Thank you very much.
--------------------------------------------
http://www.volfirst.net/~sirjorj/index.html
---------------------------------------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|