Sign in to follow this  

Detect keypress in edit box

This topic is 3932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

All right, now I've searched the forum for half an hour. I've found several threads dealing with this problem, but *no one* solving it! In my program I have an edit box where the user may write something. What I want is for the user to be able to press the enter key when he/she has finnished writing (and the edit box is still in focus). When I press enter with the box in focus it just makes a "you can't do that!" sound. I've tried having the program deal with it in the LRESULT CALLBACK WindowProcedure like this: case WM_CHAR: switch (wParam) { case 0x0D: (...) And like this: case WM_KEYDOWN: switch (wParam) { case VK_RETURN: (...) But neither WM_CHAR nor WM_KEYDOWN seem to be sent when the edit box is in focus. For the moment I've solved it by using: if (GetAsyncKeyState (VK_RETURN)) { (...) in WinMain. But this isn't really a good solution, since pressing enter still produces the "you can't do that"-sound. Please help me! As mentioned, I've searched for the solution a long time and found the problem discussed, but no one ever reached a solution!

Share this post


Link to post
Share on other sites
What do you want to happen when the user presses the enter key? What you could try is either handling the NM_RETURN message (I can never recall if the edit actually sends this) or you can subclass the edit and handle WM_CHAR in the subclassed procedure.

Also, if you are going to try handling NM_RETURN then be sure to have your edit have the ES_WANTRETURN style.

Share this post


Link to post
Share on other sites
Thank you!

I tried accepting the NM_RETURN, but didn't get that to work (maybe my edit box doesn't send the message...).

I'm to much of a beginner to know how to subclass the edit, though that's probably the best sollution. (I suppose that means I can have a separate winproc function for the edit box?) If you could explain how to do it I'd be very greatful.

Otherwise I have found an acceptable (but ugly) sollution. I used the folloing flags: ES_MULTILINE |ES_WANTRETURN | ES_AUTOVSCROLL to get rid of the annoying sound and used the GetAsyncKeyState.

(now all I have to do is to find out why my program suddenly turns itself of when it shouldn't, but that I should hopefully be able to do on my omwn!)

Share this post


Link to post
Share on other sites

This topic is 3932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this