Search code examples
cwinapi

Why doesn't the Tab key shift focus to the next control in an ES_MULTILINE styled text box?


I have created a multiline editing control with the style ES_MULTILINE and I realized that when I press the Tab key it does not change the focus to the next control.

I have IsDialogMessage and WS_TABSTOP configured, here is the code:

if (!IsDialogMessageA(hWnd, &msg))
{
    TranslateMessage(&msg);
    DispatchMessageA(&msg);
}
HWND hWndEdit1 = CreateWindowExA(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 14, 14, 200, 21, hWnd, NULL, NULL, NULL);
HWND hWndEdit2 = CreateWindowExA(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_MULTILINE | ES_WANTRETURN, 14, 44, 200, 42, hWnd, NULL, NULL, NULL);
HWND hWndEdit3 = CreateWindowExA(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 14, 95, 200, 21, hWnd, NULL, NULL, NULL);

Solution

  • Tab is a valid text character in a multi-line Edit control. It is not supposed to change focus to the next UI control. If you want Tab to do that, you will have to subclass the Edit control to handle WM_GETDLGCODE (which includes DLGC_WANTALLKEYS by default when ES_MULTILINE is enabled), or even the Tab press directly.