Calling the TranslateAccelerator Function

To process accelerators, an application's (or thread's) message loop must contain a call to the TranslateAccelerator function. TranslateAccelerator compares keystrokes to an accelerator table and, if it finds a match, translates the keystrokes into a WM_COMMAND (or WM_SYSCOMMAND) message. The function then sends the message to a window procedure. The parameters of the TranslateAccelerator function include the handle to the window that is to receive the WM_COMMAND messages, the handle to the accelerator table used to translate accelerators, and a pointer to an MSG structure containing a message from the queue. The following example shows how to call TranslateAccelerator from within a message loop.

while (GetMessage(&msg, (HWND) NULL, 0, 0)) 
{ 
    // Check for accelerator keystrokes. 
 
    if (!TranslateAccelerator( 
            hwndMain,      // handle to receiving window 
            haccel,        // handle to active accelerator table 
            &msg))         // address of message data 
    {
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
    } 
}