TAB function does not work

Hello Cplusplus,

I am working on a project and a problem has accrued. The TAB function does not work in the program (MDI windows). I got no errors when compiling nor running. The idea is that I want to chance focus on edit boxes with the TAB button.

I have tried to insert this code into my messageloop:

1
2
3
4
5
6
7
8
9
while(GetMessage(&Msg, NULL, 0, 0) > 0) { /* If no error is received... */
    
    if(!IsDialogMessage(hwnd,&Msg))
    {
        TranslateMessage(&Msg); /* Translate key codes to chars if present */
        DispatchMessage(&Msg); /* Send it to WndProc */
    }
}
return Msg.wParam;


When I have inserted the code and press the TAB button, the focus does remove from the current exit box but it just disappear and does not chance focus to the next edit box.
When I do not insert the code then I got the classic "ding" windows sound.

This is the relevant code in main.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include <windows.h>
#include <commctrl.h>
#include <stdlib.h>
#include <Windowsx.h>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <locale.h>
#include <sstream>
#include <Richedit.h>
#include <CommDlg.h>

HWND CreateNewMDIChild(HWND hMDIClient)
{
    MDICREATESTRUCT mcs;
    HWND hChild;

    mcs.szTitle = "[Untitled]";
    mcs.szClass = g_szChildClassName;
    mcs.hOwner  = GetModuleHandle(NULL);
    mcs.x = mcs.cx = CW_USEDEFAULT;
    mcs.y = mcs.cy = CW_USEDEFAULT;
    mcs.style = MDIS_ALLCHILDSTYLES;

    hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);
    if(!hChild)
    {
        MessageBox(hMDIClient, "MDI Child creation failed.", "Oh Oh...",
            MB_ICONEXCLAMATION | MB_OK);
    }
    return hChild;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
            case WM_CREATE:
        {                        
                  int statwidths[] = {100, -1};

          CLIENTCREATESTRUCT ccs;

          // Create MDI Client

          // Find window menu where children will be listed
          ccs.hWindowMenu  = GetSubMenu(GetMenu(hwnd), 5);
          ccs.idFirstChild = ID_MDI_FIRSTCHILD;

              g_hMDIClient = CreateWindowEx(WS_EX_CLIENTEDGE, "mdiclient", NULL,
                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                  hwnd, (HMENU)IDC_MAIN_MDI, GetModuleHandle(NULL), (LPVOID)&ccs);

              if(g_hMDIClient == NULL)
                MessageBox(hwnd, "Could not create MDI client.", "Error", MB_OK | MB_ICONERROR);
                        
        }
        break;
        case WM_SIZE:
        {
            HWND hMDI;
            int iMDIHeight;
            RECT rcClient;

            // Calculate remaining height and size edit

            GetClientRect(hwnd, &rcClient);

            iMDIHeight = rcClient.bottom;

            hMDI = GetDlgItem(hwnd, IDC_MAIN_MDI);
            SetWindowPos(hMDI, NULL, 0, 0, rcClient.right, iMDIHeight, SWP_NOZORDER);    
        }
        break;
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        case WM_COMMAND:
            // Some code
        default:
            return DefFrameProc(hwnd, g_hMDIClient, msg, wParam, lParam);
    }
    return 0;
}

LRESULT CALLBACK MDIChildWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CREATE:
        {
                    CreateWindow("EDIT", "", WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | WS_GROUP, 270, 40, 80, 20, hwnd, (HMENU) ID_EB_1, NULL, NULL);
                CreateWindow("EDIT", "", WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP, 270, 70, 80, 20, hwnd, (HMENU) ID_EB_2, NULL, NULL);
                CreateWindow("EDIT", "", WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP, 430, 70, 80, 20, hwnd, (HMENU) ID_EB_3, NULL, NULL);

                CreateWindow("EDIT", "", WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP, 270, 135, 80, 20, hwnd, (HMENU) ID_EB_4, NULL, NULL);
                CreateWindow("EDIT", "", WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP, 430, 135, 80, 20, hwnd, (HMENU) ID_EB_5, NULL, NULL);
        }
        break;
        case WM_COMMAND:
                    // Some code
        break;
        return DefMDIChildProc(hwnd, msg, wParam, lParam);
        default:
            return DefMDIChildProc(hwnd, msg, wParam, lParam);
    
    }
    return 0;
}

BOOL SetUpMDIChildWindowClass(HINSTANCE hInstance)
{
    WNDCLASSEX wc;

    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style        = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc    = MDIChildWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance    = hInstance;
    wc.hIcon        = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szChildClassName;
    wc.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(0, "Could Not Register Child Window", "Oh Oh...",
            MB_ICONEXCLAMATION | MB_OK);
        return FALSE;
    }
    else
        return TRUE;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    InitCommonControls();

    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style        = 0;
    wc.lpfnWndProc    = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance    = hInstance;
    wc.hIcon        = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MAINMENU);
    wc.lpszClassName = g_szClassName;
    wc.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    if(!SetUpMDIChildWindowClass(hInstance))
        return 0;

    hwnd = CreateWindowEx(
        0,
        g_szClassName,
        "Conosoft Enomi - Version 1.0.0 (beta)",
        WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
        CW_USEDEFAULT, CW_USEDEFAULT, 1100, 700,
        NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    g_hMainWindow = hwnd;

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
            if (!TranslateMDISysAccel(g_hMDIClient, &Msg))
            {
                TranslateMessage(&Msg);
                DispatchMessage(&Msg);
            }
    }
    return Msg.wParam;
}


I hope you guys can help me!
Topic archived. No new replies allowed.