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)
if (SelectedControl == hwndTxtUsername)
{
SetFocus(hwndTxtPassword);
}
if (SelectedControl == hwndTxtPassword)
{
SetFocus(hwndCheckBox);
}
if (SelectedControl == hwndCheckBox)
{
SetFocus(hwndTxtUsername);
}
}
break;
}
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?
Thanks in advance,
Sam

New Topic/Question
Reply



MultiQuote




|