Tabbing/Changing control focus

Basically how do I get to tab from one control to another.

I've looked far and wide and still can't seem to get anything working (about what I've tried later). I suspect that it may be how I've got the main window setup, as whenever I hit the tab key, when a control has the focus, I get an error beep.

What I have is a main window, to which controls are added, initially a set amount, but sets of controls can be added (this is a child support calculator, initially there's a dropdown which selects a year from a combobox, the years being extracted from a file). Then there's the adults section, For each adult, inittially two there is an edit box for the name and another for their income, each preceded by a label (readonly edit), there is also a button at the top and this when clicked adds another adult). Next is the child section, for each child there are two controls, with preceding labels, one an edit for the name, the other a check box to indicate if the child is 13+.

For a child, each adult is listed and their are two controls per adult (with labels) one a combobox to select the relationship type (Parent, other non-parent carer, parent abroad, deceased parent), the other an edit for the number of nights care the adult has for the child. Again, like with the adults, there is a button that when clicked will add another child.


What I've done.
I've got WS_TABSTOP on the controls that should get the focus.
I've got WS_EX_CONTROLPARENT on the main window and also tried it on the controls that have WS_TABSTOP. All the controls have WS_CHILD.
I can change focus after EN_KILLFOCUS (as an example for edits).
I've tried trapping the tab key via WM_KEYDOWN, this works but not if a control has the focus, as I get the error beep.

A few nudges in the right direction would be greatly appreciated.
I found the solution, very simply to implement but very hard to find, but eventually I did.

In the message processing loop you simply call IsdialogMessage and if the message was a dialog message, then don't do the TranslateMessage and the Dispatch message.

My window message processing loop was :-

1
2
3
4
5
6
7
8
9
    while (GetMessage (&messages, NULL, 0, 0) > 0)
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }
    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;


Changing it to the following works :-
1
2
3
4
5
6
7
8
9
10
11
    while (GetMessage (&messages, NULL, 0, 0) > 0)
    {
        if (!IsDialogMessage(hwnd,&messages) ) {
            /* Translate virtual-key messages into character messages */
            TranslateMessage(&messages);
            /* Send message to WindowProcedure */
            DispatchMessage(&messages);
        }
    }
    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;



As I understand it, if controls are not in a dialog then they don't automatically tab, but calling IsDialogMessage processes such messages.
Topic archived. No new replies allowed.