In my interface I have a few buttons, a combo box and a window where I display sequence of images. Those buttons navigate through the sequence, but I also wanted to navigate through the LEFT and RIGHT arrows on the keyboard. After compilation the keyboard keys work fine, because Focus is set at the main window, but after clicking a button or combo the keyboard keys doesn’t work. I manage it with SetFocus(main_hwnd) in my main loop but then the combo box doesn’t react when clicked.
Example below:
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
CreateWindowEx(0, "COMBOBOX", "", WS_CHILD | WS_VISIBLE | CBS_SORT | CBS_DROPDOWNLIST, 478, 5, 50, 200, hwnd, (HMENU)ID_COMBO1, GetModuleHandle(NULL), NULL);
break;
case WM_COMMAND:
break;
case WM_KEYDOWN:
switch(wParam)
{
case VK_SPACE:
PostQuitMessage(0);
break;
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
// SetFocus(hwnd);
return 0;
}
assumig this example:
after compilation the SPACE KEY will work, but after clicking combobox, it won’t work. If I use SetFocus(hwnd) SPACE KEY will always work but the combo box will be disabled.
Thanks for help.
Yeah, your window procedure is for that window only, a combo box is a separate window. I like to handle my hotkeys inside the message loop like so: