Amit
Amit

Reputation: 703

How to check if the user pressed a key inside a Edit controll

I have a Edit Controll (where u can write stuff) in my code, and I want that when the user will type enter (like in forms of - username / pass), it'll do something..

for example, When you logg into a site and you put ur username and pass, if you click enter, it loggs in automaticly for you, instead of clicking the "connect" button...

I have the following code :

ChatHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", NULL, WS_CHILD | WS_VSCROLL | WS_HSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_LEFT | ES_MULTILINE | ES_WANTRETURN , 15, 15, 550, 300, hwnd, NULL, 
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); // Creat chat log

It's written in Win API...

Thanks!

Upvotes: 0

Views: 288

Answers (2)

xMRi
xMRi

Reputation: 15365

If you have a Dialog the Enter key is automatically handeled in a seperate way.

If you have your own Frame Control and want in Detail a seperate Handling of the Input you have two choices:

  1. Use the message Loop and PreTranslate (I use this word from the MFC) the Input Messages.
  2. Subclass your control to get Access to all Messages that the control receives.
  3. You can use a hook (but that is Overkill)

Upvotes: 0

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10415

Remove the ES_WANTRETURN style from the control so the return key will go to the parent dialog. In the parent dialog handle the EN_KILLFOCUS notification (in WM_COMMAND). The wParam that comes with the notification will tell you if if was the edit control you are interested in.

Upvotes: 2

Related Questions