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:
ValueMeaning
0-15Specifies 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-23Specifies the scan code. The value depends on the original equipment manufacturer (OEM)
24Specifies 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-28Used internally by Windows.
29Specifies the context code. The value is 1 if the ALT key is held down while the key is pressed; otherwise, the value is 0.
30Specifies 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.
31Specifies 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值