getting 'enter' keypress when edit box has focus

Started by
6 comments, last by Endurion 18 years, 11 months ago
One last question, and my dice server is done! OK: Say I have a dialog box, with one control in it, an edit box. I need to know how to capture, within the dialog box's CALLBACK routine, when the user presses enter, and then exit the dialog - like this: Dialog box is created User enters some value User presses enter -> Dialog box closes Think something like a search engines text box where you enter the keywords into. You don't have to press a button, you can just hit enter. I'm using C++ and win32 API. Thanks.
my siteGenius is 1% inspiration and 99% perspiration
Advertisement
You can probably use somthing like the WM_KEYDOWN Notification (EDIT: and check for the VK_RETURN virtual-key code)

jfl.
no, that doesn't work. at least not when the edit control has focus, and I'm not sure if it would when it doesn't. And besides, the whole point is to be able to close it while the edit control has focus. Thanks, though.
my siteGenius is 1% inspiration and 99% perspiration
anyone else?
my siteGenius is 1% inspiration and 99% perspiration
Sorry, it's a little different with common controls. The equivalent of the WM_KEYDOWN notification is in fact NM_KEYDOWN and is sent as a WM_NOTIFY message.

jfl.
OK... I tried googling for this, but msdn wasn't very helpful and a lot of the pages were in some oriental language... How would this look? Thanks.
my siteGenius is 1% inspiration and 99% perspiration
Ok, I'm getting tired.

Edit controls do not sent WM_NOTFIY messages. From what I understand, pressing the enter key on a single-line edit control performs the default action of the dialog box. The only thing that looked remotely useful was the EN_CHANGE notification, but I'm not certain of how that would be used.

jfl.
Unless your Edit control doesn't have ES_WANTRETURN set pressing Enter will yield the same effect as pushing the default button of the dialog.
This will only work on a dialog (and using IsDialogMessage inside your message pump i think).
All you need to do is add the BS_DEFAULTBUTTON style to the button whose action you want to have done when pressing enter. No special message involved, it looks like a normal button press (WM_COMMAND).

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement