Child Windows and Messages
Below is my main message loop. I have created an Edit window as a child window of the main window. All I want to do is to be able to catch the keystrokes of the edit window (child window), but I cannot seem to figure out where to place the WM_KEYDOWN case. I have used spy++ to see the messages, and I know the WM_KEYDOWN, WM_CHAR, and WM_KEYUP messages are being fired, but I do not know where to put my message catcher. Please help me! Thanks!
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hwndEdit;
char buffer[20];
switch(iMsg)
{
case WM_CREATE:
{
hwndEdit = CreateWindow(TEXT("edit"), NULL, WS_CHILD | ES_WANTRETURN | WS_VISIBLE |
ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL, 0, 0, 0, 0,
hWnd, NULL, pWin->hInstance, NULL);
break;
}
case WM_SETFOCUS:
SetFocus (hwndEdit);
return 0;
case WM_SIZE:
MoveWindow(hwndEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
return 0;
case WM_COMMAND:
{
//SetWindowText(hWnd, _itoa(LOWORD(wParam), buffer, 10));
switch (LOWORD(wParam))
{
case VK_RETURN:
//MessageBox(NULL, _itoa(LOWORD(wParam), buffer, 10), TEXT("Command"), MB_OK);
break;
}
return 0;
}
case WM_KEYDOWN:
{
SetWindowText(hWnd, TEXT("Sucker"));
switch (wParam)
{
case VK_RETURN:
MessageBox(NULL, _itoa(LOWORD(wParam), buffer, 10), TEXT("Command"), MB_OK);
break;
}
}
case WM_CHAR:
{
SetWindowText(hWnd, TEXT("Loser"));
// switch (wParam)
// {
// case VK_RETURN:
// MessageBox(NULL, _itoa(LOWORD(wParam), buffer, 10), TEXT("Command"), MB_OK);
// break;
// }
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}