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

    response to carriage return in Edit control


    I'd like to do something when the text in an Edit control is entered and the return is hit. What message I have to handle?


  2. #2
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: response to carriage return in Edit control

    You have to place your code in the PreTranslateMessage() function as follows :

    // looking for keydown message, where key is ENTER
    // and the focus is on the edit control in question
    if (pMSG->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN && GetFocus() == GetDlgItem(IDC_EDIT_CONTROL_ID))
    {
    // enter pressed in the edit control, handle it here
    return true ;
    }
    return BaseClass::PreTranslateMessage()



    Roger Allen
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  3. #3
    Join Date
    Jun 1999
    Posts
    81

    Re: response to carriage return in Edit control

    The code would close the Dialog after pressing enter. But I'd like to keep the dialog open after hitting enter in the Edit control. Any further idea?


  4. #4
    Join Date
    May 1999
    Location
    CA, USA
    Posts
    586

    Re: response to carriage return in Edit control

    Check out Example 5 at http://home.earthlink.net/~railro/mfc_link.html.

    Rail

    Recording Engineer/Software Developer
    Rail Jon Rogut Software
    [email protected]
    http://home.earthlink.net/~railro/

  5. #5
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: response to carriage return in Edit control

    The code I posted will only intercept the ENTER key when th focus is on the edit control, to stop ENTER fromclosing your dialog box, you will need to override the OnOK() function, as pressing ENTER is mapped to this control if the default button in your dialog is the IDOK button. IF you do override it, you will have to decide when to call the base class OnOK() to close the dislog box.


    Roger Allen
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

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