Hey how do you make a your callback WindowProc() function detect when you press the 'Enter Key' from a single-line Edit Control? :confused:
Printable View
Hey how do you make a your callback WindowProc() function detect when you press the 'Enter Key' from a single-line Edit Control? :confused:
Its very insteresting......
You are able to detect 'Enter Key' pressed event on Edit control from within your WinMain() function while you takes messages through GetMessage(...) or PeekMessage(...) function.
You will get MSG structure through above two functions. MSG structure contains Window's handle and generated message. If message parameter of MSG structure is WM_KEYDOWN, wParam parameter of MSG structure is 13 and if hwnd parameter match with your edit control's handle then you can say that 'Enter Key' is pressed on Edit Control.
To make callback WindowProc() function detect when you press the 'Enter Key' from a single-line Edit Control, I will give my opinion after thinking on it.
you need the ES_WANTRETURN and this only works with the ES_MULTILINE style.
Why do you need a single line edit?
Try changing the style to mutli line and not specifying the ES_AUTOVSCROLL style.
If you really want to do this, a useful technique is subclassing. This program demonstrates it, and how to catch a few useful keys.
Nevermind :) I figured out a simpler one.
I had to opt for ES_MULTILINE though (but with no ES_AUTOVSCROLL).
Thanks anyway guys :)Code:LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message) {
case WM_COMMAND:
if(HIWORD(wParam) == EN_CHANGE && GetAsyncKeyState(13) == (-32767)) {
MessageBox(hwnd, "The Enter key has been pressed", "ALERT", MB_OK);
}
return 0;
default:
DefWindowProc(hwnd, Message, wParam, lParam);
return 0;
}
}
if(HIWORD(wParam) == EN_CHANGE && GetAsyncKeyState(13) == (-32767)) {
MessageBox(hwnd, "The Enter key has been pressed", "ALERT", MB_OK);
I think in if() condition you will also have to check for edit control's handle. Because if you have more than 1 edit controls then how can you identify even for a particular edit control ??
So.....I think you will also have to compare first parameter of WndProc() function. (i.e. HWND hwnd)
Look up Subclassing. Its better.