How to find if enter was pressed in an edit control?

This is a discussion on How to find if enter was pressed in an edit control? within the Windows Programming forums, part of the Platform Specific Boards category; Hi! How to determine if the user has pressed the enter key in an edit control? Here's my attempt, but ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102

    How to find if enter was pressed in an edit control?

    Hi!
    How to determine if the user has pressed the enter key in an edit control? Here's my attempt, but it doesn't work.

    Code:
    		
    case WM_NOTIFY:
    		if((((LPNMHDR) lparam)->code)==NM_CHAR && (((LPNMHDR) lparam)->hwndFrom)==editHwnd)
    		{
    			MessageBox(0,"ytr",0,0);
    			 if(((LPNMCHAR)lparam)->ch==VK_RETURN)
    			MessageBox(0,0,0,0);
    		}
    break;

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    You'll have to subclass the edit control

  3. #3
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    This may also be of some use:
    Quote Originally Posted by MSDN
    Specifies that a carriage return be inserted when the user presses the ENTER key while entering text into a multiline edit control in a dialog box. If you do not specify this style, pressing the ENTER key has the same effect as pressing the dialog box's default push button. This style has no effect on a single-line edit control.
    I would assume from this then that hitting the ENTER key while in a single-line edit control will also trigger the default button. Just something to look into.

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,690
    This question has been asked (and answered) many times, just search the board.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  5. #5
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102
    Ok, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Messages from edit control in MFC
    By VirtualAce in forum Windows Programming
    Replies: 0
    Last Post: 01-08-2006, 01:11 AM
  2. How can I send a text string to an edit control
    By marc74 in forum Windows Programming
    Replies: 5
    Last Post: 01-06-2005, 10:14 PM
  3. Controlling an edit control
    By master5001 in forum Windows Programming
    Replies: 2
    Last Post: 10-16-2001, 04:08 PM
  4. Edit control
    By The15th in forum Windows Programming
    Replies: 2
    Last Post: 09-25-2001, 01:36 PM
  5. Rich edit control example Win API
    By Echidna in forum Windows Programming
    Replies: 1
    Last Post: 09-17-2001, 03:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21