msgs12.hlp (Topic list)
WM_CHAR (1.2)
                                                      Up Next Previous
────────────────────────────────────────────────────────────────────────────
 
#define INCL_WININPUT
 
WM_CHAR
fsKeyFlags = (USHORT) SHORT1FROMMP(mp1);    /* key flags             */
uchRepeat = (UCHAR) CHAR3FROMMP(mp1);       /* repeat count          */
uchScanCode = (UCHAR) CHAR4FROMMP(mp1);     /* scan code             */
usChr1 = (UCHAR) CHAR1FROMMP(mp2);          /* character             */
usChr2 = (UCHAR) CHAR2FROMMP(mp2);          /* 2nd byte of character */
usVKey = (USHORT) SHORT2FROMMP(mp2);        /* virtual key           */
 
The WM_CHAR message is sent whenever the user presses a key. This message is
placed in the queue associated with the window that has the focus.
 
Parameter    Description
────────────────────────────────────────────────────────────────────────────
 
fsKeyFlags   Low word of mp1. Specifies the keyboard control codes. It can
             be one or more of the following values:
 
             Value           Meaning
             ───────────────────────────────────────────────────────────────
             KC_CHAR         The usChr parameter value is valid.
 
             KC_SCANCODE     The uchScanCode parameter value is valid;
                             otherwise, uchScanCode contains zero.
 
             KC_VIRTUALKEY   The usVKey parameter value is valid; otherwise,
                             usVKey contains zero.
 
             KC_KEYUP        The event was a key-up transition; otherwise,
                             it was a key-down transition.
 
             KC_PREVDOWN     The key was previously down; otherwise, it was
                             previously up.
 
             KC_DEADKEY      The character code is a dead key. The
                             application must display the glyph for the dead
                             key without advancing the cursor.
 
             KC_COMPOSITE    The character code was formed by combining the
                             current key with the previous dead key.
 
             KC_INVALIDCOMP  The character code was not a valid combination
                             with the preceding dead key. The application
                             must advance the cursor past the dead-key glyph
                             and then, if the current character is not a
                             space, it must beep the speaker and display the
                             new character code.
 
             KC_LONEKEY      This bit is set if the key was pressed and
                             released without any other keys being pressed
                             or released between the time the key was
                             pressed and released.
 
             KC_SHIFT        The shift state was active when the key was
                             pressed or released.
 
             KC_ALT          The ALT state was active when the key was
                             pressed or released.
 
             KC_CTRL         The CONTROL state was active when the key was
                             pressed or released.
 
uchRepeat    Low byte of high word of mp1. Specifies the repeat count of the
             key.
 
uchScanCode  High byte of high word of mp1. Specifies the character scan
             code of the character.
 
usChr1       First byte of the low word of mp2. Specifies the ASCII
             character.
 
usChr2       Second byte of the low word of mp2, for double-byte characters
             only. Specifies second byte of the character, or is zero for
             standard ASCII.
 
usVKey       High word of mp2. Specifies the virtual-key code.
 
Comments
 
Generally, all WM_CHAR messages generated from actual user input have the
KC_SCANCODE code set. However, if the message has been generated by an
application that has issued the WinSetHook function to filter keystrokes, or
if it was posted to the application queue, this code may not be set.
 
The CHARMSG macro can be used to access the WM_CHAR message parameters. This
macro defines a CHARMSG structure pointer that has the following form:
 
struct _CHARMSG {
    USHORT chr;             /* mp2 */
    USHORT vkey;
    USHORT fs;              /* mp1 */
    UCHAR  cRepeat;
    UCHAR  scancode;
};
 
When the character returned is a double-byte character, then the second byte
of mp2 contains the second byte of the character. For standard ASCII, the
second byte is zero.
 
Example
 
This example uses the CHARMSG macro to process a WM_CHAR message. It first
uses the macro to determine if a key was released. It then uses the macro to
generate a switch statement based on the character received.
 
MRESULT EXPENTRY GenericWndProc(hwnd, usMessage, mp1, mp2)
HWND   hwnd;
USHORT usMessage;
MPARAM mp1;
MPARAM mp2;
{
 
    switch (usMessage) {
    case WM_CHAR:
        if (CHARMSG(&usMessage)->fs & KC_KEYUP) {
            switch (CHARMSG(&usMessage)->chr) {
 
Return Value
 
An application should return TRUE if it processes the message; otherwise it
should return FALSE.
 
See Also
 
WinSetHook, WM_NULL, WM_TRANSLATEACCEL, WM_VIOCHAR