Click to See Complete Forum and Search --> : why this doesn't work?
Abulehleh
September 16th, 2006, 10:57 AM
i need to know when the "ENTER" ey is pressed, while the input focus was of a hwnd, lets say "edit2"..
why this doesn't work??
case WM_COMMAND:
{ switch(LOWORD(wParam))
{
case IDOK:
{
if(GetFocus()==edit2)
{
MessageBox(NULL, "enter was pressed, while focus on edit2", " ", MB_OK);
} } } }
break;
plz help..
Krishnaa
September 16th, 2006, 11:11 AM
Does the GetFocus fail ?
Abulehleh
September 16th, 2006, 11:22 AM
how do i check that?
Brenton S.
September 16th, 2006, 01:14 PM
Hi Abulehleh,
Well, what I guess you could do (while it may not be the best solution), is to use GetAsyncKeyState to see if [Enter] is being pressed and if it is, check to see if the focus lies on the edit control. Something like this:
if(GetAsyncKeyState(VK_RETURN) & 0x8000)
{HWND hwndFocus;
hwndFocus = GetFocus();
if(hwndFocus == hwndEdit)
{// Do something
}
}
Hope that helps. :wave:
Abulehleh
September 16th, 2006, 01:51 PM
yeah! that helped alot! thanks!
Abulehleh
September 17th, 2006, 03:11 PM
Actually, after trying it a few times, i stumbled a serious error..
because it is in my msg loop, when i press the enter (in it stays down for lets say 0.2 seconds) the msg of "//do something" repeat itself- in my programm, the message board (where all the message recieved and sent are shown, it shows about 5 blank messages..)
so basically the point is to press the enter key once, not to check when it's down,. to check when it is presswed..
any other ideas or improvement for this idea?
thanks!
greg_dolley
September 18th, 2006, 06:07 AM
any other ideas or improvement for this idea?
With your original code where you were handling the OK command, are you sure the "OK" button was set as default in the form? If it was, then your code should have worked perfectly.
Greg Dolley
Abulehleh
September 18th, 2006, 04:43 PM
well it didnt, anyway i have found a solution.. simply dont send anything of null lenghts.. so only writtend content is sent and the enter can be pressed as many as the user wants- if the field is empty there will be nothing going on..
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.