MFC Return key closing dialog box
In my dialog-based MFC application, i have the main dialog box creating child dialog boxes. In these child dialog boxes, I have CEdit controls to enter information. I want to be able to press the enter key in these edit controls after typing information into them and call an event such as a button click (so when the user types in the edit control, they can press enter rather than use the mouse to click on the button).
Currently, pressing the enter key in a child dialog closes the dialog. What would be the best way to go about doing this?
[555 byte] By [
zimmer_04] at [2007-11-20 7:07:24]

# 1 Re: MFC Return key closing dialog box
Check out CDialog's SetDefID function. It changes the default ID, so you can re-assign it to a different control if you'd like.
# 2 Re: MFC Return key closing dialog box
If I'm understanding this function right, using this means that if i hit the enter key anywhere in the dialog box, it will call the event for whatever IDC I pass in.
This might work, but do you have any other suggestions?
# 3 Re: MFC Return key closing dialog box
Actually I have it figured out now. I created a button with ID of IDOK (since that is the default control) and I will just handle that event. Thanks for the help.
# 4 Re: MFC Return key closing dialog box
Creating an IDOK button is an acceptable solution, but if it is not, in fact, an "OK" button for the dialog I would recommend using the SetDefID method and reserving the IDOK ID for the actual OK Button.
Cheers
-eli