Making TAB key work in my win32 app

c++, codeblocks, winapi

Solution

The fix is quite simple. Given the fact you're handling the WM_CREATE message, rather than the WM_INITDIALOG message, it seems safe to assume that you're adding the controls to a 'standard' window, rather than a 'dialog'.

With that in mind, I expect you've got something like the following in your winmain:

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
    /* Translate virtual-key messages into character messages */
    TranslateMessage(&messages);
    /* Send message to WindowProcedure */
    DispatchMessage(&messages);
}

However, the documentation for `IsDialogMessage` states:

"Although the IsDialogMessage function is intended for modeless dialog boxes, you can use it with any window that contains controls, enabling the windows to provide the same keyboard selection as is used in a dialog box. When IsDialogMessage processes a message, it checks for keyboard messages and converts them into selection commands for the corresponding dialog box. For example, the TAB key, when pressed, selects the next control or group of controls, and the DOWN ARROW key, when pressed, selects the next control in a group.

Because the IsDialogMessage function performs all necessary translating and dispatching of messages, a message processed by IsDialogMessage must not be passed to the TranslateMessage or DispatchMessage function."

So, you can change your message pump to resemble the following:

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
    /* Translate virtual-key messages into character messages */
    if (IsDialogMessage(hwnd, &messages) == 0)
    {
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }
}

Problem

I want to make the tab button work on my app , so when I press tab, it will change from one edit box to another, these are the edit box codes: ``` case WM_CREATE: TextBox = CreateWindow("EDIT", "", WS_BORDER|WS_CHILD|WS_VISIBLE|WS_EX_LAYERED|WS_TABSTOP|WS_GROUP, 60,50,200,20, hwnd,NULL,NULL,NULL); DataBox = CreateWindow("EDIT", "", WS_BORDER|WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP, 60,72,200,20, hwnd,NULL,NULL,NULL); MotivBox = CreateWindow("EDIT", "", WS_BORDER|WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP, 60,92,200,20, hwnd,NULL,NULL,NULL); PretBox = CreateWindow("EDIT", "", WS_BORDER|WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP, 60,112,200,20, hwnd,NULL,NULL,NULL); ```

Original source