How to correctly trap "Enter" key in MFC dialog ?
-
What is the correct way to do this, I have a dialog and when I hit enter after editing a number in an edit box, it's acting like another button is being pressed even though that's not active by tab order or whatever. I'm sure I remember seeing a way that you could trap the Enter key so it doesn't do anything unexpected t.i.a Lee
-
What is the correct way to do this, I have a dialog and when I hit enter after editing a number in an edit box, it's acting like another button is being pressed even though that's not active by tab order or whatever. I'm sure I remember seeing a way that you could trap the Enter key so it doesn't do anything unexpected t.i.a Lee
See if this helps.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
What is the correct way to do this, I have a dialog and when I hit enter after editing a number in an edit box, it's acting like another button is being pressed even though that's not active by tab order or whatever. I'm sure I remember seeing a way that you could trap the Enter key so it doesn't do anything unexpected t.i.a Lee
-
See if this helps.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
thanks, I have OnOk and OnCancel managed manually, and my program correctly exits via the red X button on the title bar, and through File->Exit my problem is not that the dialog is closing but that pressing the Enter key while in an edit control is somehow activating a press of another button thats adding that data to a listview elsewhere. Since the user is typing into the edit control, I assumed the focus was there, so don't understand how that is turning into the same action as pressing this other button (that is not at the top of the tab order tree, so it's not like it's defaulting to that)
-
When you press enter the framework calls the default action for OK (just like pressing the IDOK button). So you either have to override OnOk method or set that edit box to "Want Return"(which you can do from the Properties window)
no, it's not exiting, it's acting like a button is being pressed. the edit control is Tab oRder 5, contains a number, there is another numeric edit at tab order 6, then tab order 7 is a button which adds some calculated data to a listview report. hitting enter after the data in edit box 5 is causing the data to be added to the table. Is there any way I can track what's causing this?
-
thanks, I have OnOk and OnCancel managed manually, and my program correctly exits via the red X button on the title bar, and through File->Exit my problem is not that the dialog is closing but that pressing the Enter key while in an edit control is somehow activating a press of another button thats adding that data to a listview elsewhere. Since the user is typing into the edit control, I assumed the focus was there, so don't understand how that is turning into the same action as pressing this other button (that is not at the top of the tab order tree, so it's not like it's defaulting to that)
Does the edit control have the
ES_WANTRETURN
style?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Does the edit control have the
ES_WANTRETURN
style?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
I've tried it with (by setting the "want return" style in the visual dialog editor) and without (which is was before). same result!
-
I've tried it with (by setting the "want return" style in the visual dialog editor) and without (which is was before). same result!
Fair enough. Without walking through the code myself, I've no more suggestions.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I've tried it with (by setting the "want return" style in the visual dialog editor) and without (which is was before). same result!
OK, removing the "default button" style now works, but NOW it closes the dialog, even though I have overridden the OnOk and OnCancel functions.
-
OK, removing the "default button" style now works, but NOW it closes the dialog, even though I have overridden the OnOk and OnCancel functions.
which is fine, I've now stopped OnOk from closing the diagram thanks chaps!
-
no, it's not exiting, it's acting like a button is being pressed. the edit control is Tab oRder 5, contains a number, there is another numeric edit at tab order 6, then tab order 7 is a button which adds some calculated data to a listview report. hitting enter after the data in edit box 5 is causing the data to be added to the table. Is there any way I can track what's causing this?