Compartir a través de


CWnd::OnChar

The framework calls this member function when a keystroke translates to a nonsystem character.

afx_msg void OnChar(
   UINT nChar,
   UINT nRepCnt,
   UINT nFlags 
);

Parameters

  • nChar
    Contains the character code value of the key.

  • nRepCnt
    Contains the repeat count, the number of times the keystroke is repeated when user holds down the key.

  • nFlags
    Contains the scan code, key-transition code, previous key state, and context code, as shown in the following list:

    Value

    Meaning

    0-15

    Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user holding down the key.

    16-23

    Specifies the scan code. The value depends on the original equipment manufacturer (OEM)

    24

    Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.

    25-28

    Used internally by Windows.

    29

    Specifies the context code. The value is 1 if the ALT key is held down while the key is pressed; otherwise, the value is 0.

    30

    Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.

    31

    Specifies the transition state. The value is 1 if the key is being released, or it is 0 if the key is being pressed.

Remarks

This function is called before the OnKeyUp member function and after the OnKeyDown member function are called. OnChar contains the value of the keyboard key being pressed or released.

Because there is not necessarily a one-to-one correspondence between keys pressed and OnChar calls generated, the information in nFlags is generally not useful to applications. The information in nFlags applies only to the most recent call to the OnKeyUp member function or the OnKeyDown member function that precedes the call to OnChar.

For IBM Enhanced 101- and 102-key keyboards, enhanced keys are the right ALT and the right CTRL keys on the main section of the keyboard; the INS, DEL, HOME, END, PAGE UP, PAGE DOWN, and arrow keys in the clusters to the left of the numeric keypad; and the slash (/) and ENTER keys in the numeric keypad. Some other keyboards may support the extended-key bit in nFlags.

Nota

This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.

Requirements

Header: afxwin.h

See Also

Reference

CWnd Class

Hierarchy Chart

WM_CHAR

CWnd::OnKeyDown

CWnd::OnKeyUp

Concepts

CWnd Members