MSDN中关于CWnd::OnChar()帮助有误?

MSDN中关于CWnd::OnChar()帮助有误?

需要将窗体的OnChar消息传递给内含的子窗体,按MSDN解释:
nFlags等同于LParam的值,于是按如下进行传递
SendMessage(WM_CHAR, nChar,  nFlags)
结果发现传到子窗体中的nRepCnt不正确。

看看OnChar帮助(见下),对于nFlags,MSDN中的Contains中并未包含nRepCnt,而下面的列
表中确自相毛盾,将低字解释为nRepCtrl。可能是从WM_CHAR中的LParam中抄过来的吧?
并且,如果真的包含的话,也不符合MFC一贯做法,且包含了冗余数据。

再查了一下COleControl::OnChar中的做法:
DefWindowProc(WM_CHAR, nChar, MAKELONG(nRepCnt, nFlags));
所以,它也是把LParam拆成高低字,然后分别给nRepCnt和nFlags的。

跟踪了一下CWnd::OnChar中的nFlags返回,实际上返回的是扫描码。
其值等同于键盘的基本分布次序。如数字1返回2,数据2返回3,依次
从左到右,从上到下。

所以,呵呵,应该是MSDN的笔误吧。查了一下网上的MSDN,也是
这样写的。见下面的说明。

所以,转发时,正确写法所以是:(需重组LPARAM)
SendMessage(WM_CHAR, nChar, MAKELONG(nRepCnt, nFlags))

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.

Syntax

WM_CHAR

    WPARAM wParam
    LPARAM lParam;
    

Parameters

wParam
Specifies the character code of the key.
lParam
Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table.
0-15
Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
16-23
Specifies the scan code. The value depends on the 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
Reserved; do not use.
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.

你可能感兴趣的:(MSDN中关于CWnd::OnChar()帮助有误?)