Search code examples
windowsapidialogarrow-keys

Navigate in Windows Dialog with arrow keys


I am using plain Windows API. I would like to navigate between the Textboxes of a Dialog using arrow keys VK_UP, VK_DOWN. VK_LEFT, VK_RIGHT. I have subclassed the Textboxes in order to get the WM_CHAR, and I get every keystroke, including backspace, delete, etc but no arrow keys! What am I doing wrong? Thanks for advice!

    //subclassing
SetWindowSubclass(GetDlgItem(hDlg, IDC_TEXTBOX1),TextBoxProc, IDC_TEXTBOX1,param);

with

LRESULT CALLBACK
TextBoxProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam,
             UINT_PTR Id, DWORD_PTR param)
{
    switch (msg)
    {
       case WM_CHAR:
            char c= (char)wParam;
etc
}

Solution

  • It should be WM_KEYDOWN instead of WM_CHAR

    LRESULT CALLBACK TextBoxProc(
        HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT_PTR, DWORD_PTR)
    {
        switch (msg)
        {
        case WM_KEYDOWN:
        {
            if (wParam == VK_DOWN)
            {
                OutputDebugString(L"VK_DOWN\n");
                return TRUE;// or break!
            }
            break;
        }
        default:break;
        }
    
        return DefSubclassProc(hWnd, msg, wParam, lParam);
    }