WinAPI WM_KEYDOWN not being sent by editbox

Posted 09 January 2013 - 07:22 AM

Hey />
I'm having a problem with catching inputs from the user. The intended effect is that each time the user presses the Tab key, the active focus of the program will be sent to the next control. Currently, when I press the tab key and no control is selected, the focus moves to the first control, which works fine:

case WM_KEYDOWN:
{
if (toascii(LOWORD(wParam)) == toascii(9))
{
HWND SelectedControl;
SelectedControl = GetFocus();
if (SelectedControl == hwnd) //I use hwnd here because the default value when nothing is selected is the address
{ // of the main form
SetFocus(hwndTxtUsername);
}

This all works fine, and when I press tab for the first time, the hwndTxtUsername is selected, and the typing cursor appears. However, once the hwndTxtUsername is selected, it no longer recognises that the Tab key is being pressed (I conformed this by sending a message to cout when tab is pressed, which only outputs the first time tab is pressed)

None of the above code executes once the focus of the program is in the first edit box. Also, when I click a button on the form which removes focus from the textbox, tab is once again recognised until it passes focus back to the text box.
I can only assumed that to prevent random hotkeys being pressed whilst typing in an editbox, the WM_KEYDOWN message isn't sent to the processor when focus is on an editbox? Can anyone think of a way around this?

Re: WinAPI WM_KEYDOWN not being sent by editbox

Posted 09 January 2013 - 09:50 AM

The default behavior of the Edit and RichEdit controls is to switch focus from the current edit control to the next control in a dialog. Something is dramatically wrong if you need to do this manually.