how do you know when enter is pressed?

This is a discussion on how do you know when enter is pressed? within the Windows Programming forums, part of the Platform Specific Boards category; Hey, i have an edit control, and i want to call a certain function when enter is pressed. How can ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    112

    how do you know when enter is pressed?

    Hey, i have an edit control, and i want to call a certain function when enter is pressed. How can i tell when enter is pressed and the edit control has focus?

    Why doesn't anything happen with the code below:
    case WM_KEYDOWN:
    MessageBox(hwnd, "key pressed", "", MB_OK);
    break;

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Check for the following message

    WM_GETDLGCODE:

    Then in response to that message,

    return( DLGC_WANTALLKEYS );

    so .. to recap, just add this.
    Code:
    case WM_GETDLGCODE:
         return( DLGC_WANTALLKEYS );
    throw that in your dlgproc. Good luck.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    That's really cool! Much simpler than what I've been doing...
    Code:
    #include <ip.hpp>

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    I'm having a hard time trying to figure this one out. What do you do after you'e added that. Are you supposed to add some code inside of the case?

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    Never mind, i figured out a good way of doing this. I just made a hidden button and gave it the default style. So now when ever enter is pressed the button is called and i check to see if the edit box has focus.

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    36

    Unhappy

    Heya all, sorry I bump this ooold thread...

    But I want to do the same as pinkcheese (get a notify if the user presses <enter> in a single line edit control)

    And the suggestions of this thread don't work in my prog.

    I have a application that consist only of one modal dialog that is called on startup (well not quite, there's the main window where the user can set things up and then click a button to open the dialog; but the dialog is the main part of the app)

    I created the edit in the source with CreateWindowEx.

    There's no WM_KEYDOWN messages coming from the edit. I also have tried to make a button with the BS_DEFPUSHBUTTON style, but it only fires its function when clicked, not when I press Enter somewhere in the diag.

    plz help I'll post code if you need it to see; just tell me which section of the code you wanna see.

    Thx,

    PrivatePanic
    "I don't know with what weapons World War III will be fought... but World War IV will be fought with sticks and stones." - Albert Einstein

  7. #7
    Registered User
    Join Date
    Jul 2002
    Posts
    36
    I got it!


    The solution: Subclassing!



    if anyone needs that, too, I'll post a link to a cool Tut that helped me.
    "I don't know with what weapons World War III will be fought... but World War IV will be fought with sticks and stones." - Albert Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help With a BlackJack Program in C
    By Jp2009 in forum C Programming
    Replies: 15
    Last Post: 03-30-2009, 10:06 AM
  2. Assignment output help
    By Taka in forum C Programming
    Replies: 13
    Last Post: 09-23-2006, 11:40 PM
  3. endless loop for scanf - plz help
    By owi_just in forum C Programming
    Replies: 18
    Last Post: 03-20-2005, 12:41 PM
  4. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 10:31 PM
  5. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 03-31-2003, 11:23 PM

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