-
April 16th, 2007, 02:32 PM
#1
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?
-
April 16th, 2007, 02:36 PM
#2
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.
-
April 16th, 2007, 02:46 PM
#3
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?
-
April 16th, 2007, 03:01 PM
#4
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.
-
April 16th, 2007, 03:19 PM
#5
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
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
|