When a user enters a character, Windows CE does not automatically generate a character message. Instead, it generates a keystroke message. To translate a keystroke message into a corresponding character message, the application message loop must call the TranslateMessage function. This function examines the virtual-key code of a keystroke message and, if the code corresponds to a character, places a character message into the message queue. The character message is removed and dispatched on the next iteration of the message loop.
The message loop should call the TranslateMessage function to translate every message, not just keystroke messages. Although TranslateMessage has no effect on other types of messages, using it ensures that keyboard input is translated correctly. The following code example shows how to include the TranslateMessage function in a typical thread message loop.
while (GetMessage(&msg, (HWND) NULL, 0, 0))
{
if (TranslateAccelerator(hwndMain, haccl, &msg) == 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Windows CE includes four character messages: WM_CHAR, WM_SYSCHAR, WM_DEADCHAR, and WM_SYSDEADCHAR. A typical window procedure ignores all character messages except WM_CHAR. The WM_CHAR message contains the character code and the flags that provide additional data about the character.
When a window procedure receives the WM_CHAR message, it should examine the character code that accompanies the message to determine how to process the character. The character code is in the message wParam parameter.
The following code example shows the window procedure framework that a typical application uses to receive and process character messages.
while (GetMessage (&msg, (HWND)NULL, 0, 0))
{
if (TranslateAccelerator (hwndMain, haccl, &msg) == 0)
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}