36.2.3 Processing Character Messages

A window procedure receives a character message when the TranslateMessage function translates a virtual-key code corresponding to a character key. The character messages consist of WM_CHAR, WM_DEADKEY, WM_SYSCHAR, and WM_SYSDEADKEY. A typical window procedure ignores all character messages except WM_CHAR. The TranslateMessage function generates a WM_CHAR message when the user presses any of the following keys:

Any character key
BACKSPACE
ENTER (carriage return)
ESC
SHIFT+ENTER (line feed)
TAB

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's wParam parameter.

The following code fragment shows the window-procedure framework that a typical application uses to receive and process character messages:

case WM_CHAR:

switch (wParam) {

case 0x08:

.

. /* Process backspace. */

.

break;

case 0x0A:

.

. /* Process line feed. */

.

break;

case 0x1B:

.

. /* Process escape. */

.

break;

case 0x09:

.

. /* Process tab. */

.

break;

case 0x0D:

.

. /* Process carriage return. */

.

break;

default:

.

. /* Process displayable characters. */

.

break;

}