Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function processes accelerator keys for menu commands. TranslateAcceleratortranslates a WM_KEYDOWNor WM_SYSKEYDOWNmessage to a WM_COMMANDmessage and then sends the WM_COMMAND message directly to the appropriate window procedure. TranslateAcceleratordoes not return until the window procedure has processed the message.

Syntax

int TranslateAccelerator(
  HWND 
hWnd, 
  HACCEL 
hAccTable, 
  LPMSG 
lpMsg 
);

Parameters

hWnd

Handle to the window whose messages are to be translated.

hAccTable

Handle to an accelerator table. The accelerator table must have been loaded by a call to the LoadAcceleratorsfunction or created by a call to the CreateAcceleratorTablefunction.

lpMsg

Long pointer to an MSGstructure that contains message information retrieved from the calling thread's message queue by using the GetMessageor PeekMessagefunction.

Return Value

Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.

Remarks

All accelerator key messages are translated into WM_COMMAND messages; Windows Embedded CE does not support the WM_SYSCOMMAND message.

To differentiate the message that this function sends from messages sent by menus or controls, the high-order word of the wParamparameter of the WM_COMMAND or WM_SYSCOMMAND message contains the value 1.

Accelerator key combinations used to select items from the windowmenu are translated into WM_SYSCOMMAND messages; all other accelerator key combinations are translated into WM_COMMAND messages.

When TranslateAcceleratorreturns a nonzero value and the message is translated, the application should not use the TranslateMessagefunction to process the message again.

An accelerator need not correspond to a menu command.

If the accelerator command corresponds to a menu item, the application is sent a WM_INITMENUPOPUPmessage, as if the user were trying to display the menu. However, these messages are not sent if any of the following conditions exist:

  • The window is disabled.

  • The menu item is disabled.

  • The accelerator key combination does not correspond to an item on the windowmenu and the window is minimized.

  • A mouse capture is in effect. For information about mouse capture, see the SetCapturefunction.

If the specified window is the active window and no window has the keyboard focus (which is generally the case if the window is minimized), TranslateAcceleratortranslates WM_SYSKEYUPand WM_SYSKEYDOWN messages instead of WM_KEYUP and WM_KEYDOWN messages.

If an accelerator keystroke occurs that corresponds to a menu item when the window that owns the menu is minimized, TranslateAcceleratordoes not send a WM_COMMAND message. However, if an accelerator keystroke occurs that does not match any of the items in the window's menu or in the windowmenu, the function sends a WM_COMMAND message, even if the window is minimized.

Requirements

Header winuser.h
Library Accel.lib
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also