The TranslateMessage function translates virtual-key messages into character messages. The character messages are posted to the calling thread's message queue, to be read the next time the thread calls the GetMessage or PeekMessage function.
Syntax
BOOL TranslateMessage(
const MSG *lpMsg
);
Parameters
- lpMsg
-
[in] Pointer to an MSG structure that contains message information retrieved from the calling thread's message queue by using the GetMessage or PeekMessage function.
Return Value
If the message is translated (that is, a character message is posted to the thread's message queue), the return value is nonzero.
If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the return value is nonzero, regardless of the translation.
If the message is not translated (that is, a character message is not posted to the thread's message queue), the return value is zero.
Remarks
The TranslateMessage function does not modify the message pointed to by the lpMsg parameter.
WM_KEYDOWN and WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message. WM_SYSKEYDOWN and WM_SYSKEYUP combinations produce a WM_SYSCHAR or WM_SYSDEADCHAR message.
TranslateMessage produces WM_CHAR messages only for keys that are mapped to ASCII characters by the keyboard driver.
If applications process virtual-key messages for some other purpose, they should not call TranslateMessage. For instance, an application should not call TranslateMessage if the TranslateAccelerator function returns a nonzero value. Note that the application is responsible for retrieving and dispatching input messages to the dialog box. Most applications use the main message loop for this. However, to permit the user to move to and to select controls by using the keyboard, the application must call IsDialogMessage. For more information, see Dialog Box Keyboard Interface.
Windows 95/98/Me: TranslateMessage is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.
Example
For an example, see Creating a Message Loop.
Function Information
| Minimum DLL Version | user32.dll |
|---|
| Header | Declared in Winuser.h, include Windows.h |
|---|
| Import library | User32.lib |
|---|
| Minimum operating systems |
Windows 95, Windows NT 3.1 |
|---|
See Also
Messages and Message Queues Overview,
GetMessage,
IsDialogMessage,
PeekMessage,
TranslateAccelerator,
WM_CHAR,
WM_DEADCHAR,
WM_KEYDOWN,
WM_KEYUP,
WM_SYSCHAR,
WM_SYSDEADCHAR,
WM_SYSKEYDOWN,
WM_SYSKEYUP