TranslateAccelerator

  int TranslateAccelerator(hwnd, haccl, lpmsg)    
  HWND hwnd; /* handle of destination window */
  HACCEL haccl; /* handle of accelerator table */
  LPMSG lpmsg; /* address of structure with message */

The TranslateAccelerator function processes accelerators for menu commands. The function translates a WM_KEYDOWN or WM_SYSKEYDOWN message to a WM_COMMAND or WM_SYSCOMMAND message, if there is an entry for the key in the specified accelerator table, and then sends the WM_COMMAND or WM_SYSCOMMAND message directly to the appropriate window procedure. TranslateAccelerator does not return until the window procedure has processed the message.

Parameters

hwnd

Identifies the window whose messages are to be translated.

haccl

Identifies an accelerator table. The accelerator table must have been loaded by a previous call to the LoadAccelerators function or created by a previous call to the CreateAcceleratorTable function.

lpmsg

Points to an MSG structure that contains message data retrieved from the calling thread's message queue by using the GetMessage or PeekMessage function. The MSG structure has the following form:

typedef struct tagMSG { /* msg */

HWND hwnd;

UINT message;

WPARAM wParam;

LPARAM lParam;

DWORD time;

POINT pt;

} MSG;

Return Value

The return value is TRUE if translation occurs. Otherwise, it is FALSE. Use the GetLastError function to obtain extended error information.

Comments

The high-order word of the lParam parameter of the WM_COMMAND or WM_SYSCOMMAND message contains the value 1, to differentiate the message from messages sent by menus or controls.

Accelerator keystrokes that are defined to select items from the System menu are translated into WM_SYSCOMMAND messages; all other accelerators are translated into WM_COMMAND messages.

When TranslateAccelerator returns a nonzero value (meaning that the message is translated), the application should not process the message again by using the TranslateMessage function.

An accelerator need not correspond to a menu command.

If the accelerator command does correspond to a menu item, the application is sent WM_INITMENU and WM_INITMENUPOPUP messages, just as if the user were trying to display the menu. However, these messages are not sent if any of the following conditions are present:

The window is disabled.

The menu item is disabled.

The accelerator keystroke does not correspond to an item on the System menu and the window is minimized.

A mouse capture is in effect. For more information about mouse capture, see the description of the SetCapture function.

If the window is the active window and no window has the keyboard focus (generally the case if the window is minimized), WM_SYSKEYUP and WM_SYSKEYDOWN messages are translated instead of WM_KEYUP and WM_KEYDOWN messages.

If an accelerator keystroke that corresponds to a menu item occurs when the window that owns the menu is minimized, no WM_COMMAND message is sent. However, if an accelerator keystroke that does not match any of the items on the window's menu or the System menu occurs, a WM_COMMAND message is sent, even if the window is minimized.

See Also

CreateAcceleratorTable, GetMessage, LoadAccelerators, PeekMessage, SetCapture