CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2007
    Posts
    11

    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?

  2. #2
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658

    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.
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

  3. #3
    Join Date
    Feb 2007
    Posts
    11

    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?

  4. #4
    Join Date
    Feb 2007
    Posts
    11

    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.

  5. #5
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658

    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
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured