How to get KeyPessed event from an editbox
-
Here is my event handling code:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: Init(); case WM_PAINT: PaintScreen(); break; case WM_CLOSE : DestroyWindow(hwnd); break; case WM_KEYDOWN: if(wParam == 13){ ProcessCommand(); } case WM_COMMAND : if(LOWORD(wParam) == ID_COMMAND) ProcessCommand(); break; case WM_DESTROY : PostQuitMessage(0); break; } return DefWindowProc(hwnd, msg, wParam, lParam); }
This only works if the main window has the focus, so how can i check which key was pressed if the editbox (ID_EDITBOX) has the focus. Ie so that if the user presses enter i can run the proccessing needed on it. -
Here is my event handling code:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: Init(); case WM_PAINT: PaintScreen(); break; case WM_CLOSE : DestroyWindow(hwnd); break; case WM_KEYDOWN: if(wParam == 13){ ProcessCommand(); } case WM_COMMAND : if(LOWORD(wParam) == ID_COMMAND) ProcessCommand(); break; case WM_DESTROY : PostQuitMessage(0); break; } return DefWindowProc(hwnd, msg, wParam, lParam); }
This only works if the main window has the focus, so how can i check which key was pressed if the editbox (ID_EDITBOX) has the focus. Ie so that if the user presses enter i can run the proccessing needed on it. -
How would i go about using the EN_CHANGE notifcation? As checking for it in the switch case does not work as the code is not executed when i key is pressed.
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: Init(); case WM_PAINT: PaintScreen(); break; case WM_CLOSE : DestroyWindow(hwnd); break; case WM_KEYDOWN: if(wParam == 13){ ProcessCommand(); } break; case EN_CHANGE: if(wParam == 13){ ProcessCommand(); } break; case WM_COMMAND : if(LOWORD(wParam) == ID_COMMAND) ProcessCommand(); break; case WM_DESTROY : PostQuitMessage(0); break; } return DefWindowProc(hwnd, msg, wParam, lParam); }
-
How would i go about using the EN_CHANGE notifcation? As checking for it in the switch case does not work as the code is not executed when i key is pressed.
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: Init(); case WM_PAINT: PaintScreen(); break; case WM_CLOSE : DestroyWindow(hwnd); break; case WM_KEYDOWN: if(wParam == 13){ ProcessCommand(); } break; case EN_CHANGE: if(wParam == 13){ ProcessCommand(); } break; case WM_COMMAND : if(LOWORD(wParam) == ID_COMMAND) ProcessCommand(); break; case WM_DESTROY : PostQuitMessage(0); break; } return DefWindowProc(hwnd, msg, wParam, lParam); }