简体   繁体   English

获取 WM_KEYDOWN 消息中 lParam 参数的第 30 位

[英]Get 30th bit of the lParam param in WM_KEYDOWN message

I need to get the 30th bit of the lParam param passed with the WM_KEYDOWN message.我需要通过 WM_KEYDOWN 消息获取 lParam 参数的第 30 位。 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 .我只会使用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).如果那不是零,则设置了b30 (顺便说一下,我认为是 32 的30 位)。 And there's more likelihood that it will be a {logical-and, compare} operation rather than {shift, logical-and, compare} .而且它更有可能是{logical-and, compare}操作而不是{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?请注意,即使您使用(lParam >> 30) & 1 ,一个体面的编译器也很有可能生成更高效的代码,但为什么要冒险呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM