Providing access to the GUI through the keyboard (Xp, Visual Studio, C ++)

I created a GUI with a button, button groups, edits, lists ... etc ... but now I want to know how to make my gui accessible via keyboard, I mean changing focus by clicking a tab button. Does anyone know how to do this? I am using Windows Xp and the GUI is written in C ++ using Visual Studio 2008.

Thank you so much

UPDATE:

INT APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: Place code here.
    MSG msg;
    HACCEL hAccelTable;

    INITCOMMONCONTROLSEX ics;
    ics.dwSize = sizeof(ics);
    ics.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&ics);

    // Initialize global strings
    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadString(hInstance, IDC_PRUEBA, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }

    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_ACCEL_TABLE));

    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if ((!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) && (!IsDialogMessage(msg.hwnd, &msg))) 
        //if ((!IsDialogMessage(msg.hwnd, &msg)) & (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg) )) 
        //if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}

      

I have a lot of controls in my GUI, should I include WS_TABSTOP in all of them? What if I have a group of buttons ... should I put a WS_TABSTOP in each button and in the group? only in individual buttons?

For example, I will insert the group that I created:

INT CrearControles(HWND hwnd, LPARAM lParam) {
    HINSTANCE hInstance;
    HFONT hfont;
    HWND hctrl;
    int i;

    hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
    hfont = (HFONT)GetStockObject( DEFAULT_GUI_FONT );

    /* Insertar controles */    
    hctrl = CreateWindowEx(
        0,
        "BUTTON",        /* Nombre de la clase */
        "Rol",       /* Texto del título */
        BS_GROUPBOX | WS_CHILD | WS_VISIBLE | WS_GROUP , /* Estilo */
        20, 15,           /* Posición */
        180, 100,          /* Tamaño */
        hwnd,            /* Ventana padre */
        (HMENU)GRUPO_ROL,/* Identificador del control */
        hInstance,       /* Instancia */
        NULL);           /* Sin datos de creación de ventana */ 
    SendMessage(hctrl, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0));

    hctrl = CreateWindowEx(0, "BUTTON", "Receptor", BS_NOTIFY | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 30, 35,
      70, 25, hwnd, (HMENU)BOTON_RECEPTOR, hInstance, NULL);           
    SendMessage(hctrl, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0));
    SendDlgItemMessage(hwnd, BOTON_RECEPTOR, BM_SETCHECK, BST_CHECKED, 0);           
    SetFocus(hctrl);

    hctrl = CreateWindowEx(0, "BUTTON", "Emisor", BS_NOTIFY | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 30, 65,
      70, 25, hwnd, (HMENU)BOTON_EMISOR, hInstance, NULL);         
    SendMessage(hctrl, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0));


    hctrl = CreateWindowEx(0, "STATIC", "Telefono", SS_SIMPLE | WS_CHILD | WS_VISIBLE, 150, 55, 100, 55, hwnd, (HMENU)LABEL_TELEFONO,
          hInstance, NULL);          
    SendMessage(hctrl, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0));
    SetFocus(hctrl); 

    hctrl = CreateWindowEx(0, "EDIT", "", ES_READONLY | ES_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | ES_NUMBER , 115, 68,
          80, 20, hwnd, (HMENU)EDIT_TELEFONO, hInstance, NULL); 
    SendMessage(hctrl, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0));
    SetFocus(hctrl);       

    return 1;
}

      

thank

+2


source to share


1 answer


If you're using the GUI like a standard modal dialog, you should get tabbing and Alt keys to manipulate controls for free.

those. controls with the WS_TABSTOP styleset with which you should be able to inject tabs, key-keyed controls (for example: a button labeled "& Do Something" should be accessible with Alt + D - and D should be underlined).

If your window does not act as a standard modal dialog, to get this behavior, your message loop must call IsDialogMessage before sending each message.



eg:

MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
    if (!IsDialogMessage(m_hWndYourWindow, &msg))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

      

+3


source







All Articles