在WM_KEYDOWN消息中获取lParam参数的第30位 [英] Get 30th bit of the lParam param in WM_KEYDOWN message

查看:251
本文介绍了在WM_KEYDOWN消息中获取lParam参数的第30位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取通过WM_KEYDOWN消息传递的lParam参数的第30位。此位写入此处允许我知道键是否被按下。这个代码是否正确?

 (lParam>> 30)& 1 


解决方案

lParam& 0x40000000 。如果这不是零,那么设置 b30 (我认为三十二的三十个位,顺便说一句)。更有可能是 {logical-and,compare} 操作,而不是 {shift,logical-and,compare} (lParam),你也可以使用一个合适的编译器生成更高效的代码。 >> 30)& 1 但为什么要承担风险?


I need to get the 30th bit of the lParam param passed with the WM_KEYDOWN message. This bit as written here allows me to know if the key was pressed before. Is this code right to get it?

(lParam >> 30) & 1

解决方案

I would just use lParam & 0x40000000. If that's non-zero, then b30 was set (I consider that the thirty first bit of the thirty two, by the way). And there's more likelihood that it will be a {logical-and, compare} operation rather than {shift, logical-and, compare}.

Mind you, there's a good chance that a decent compiler would generate the more efficient code anyway even if you used (lParam >> 30) & 1 but why take the risk?

这篇关于在WM_KEYDOWN消息中获取lParam参数的第30位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆