分手LPARAM可变的放大器;看着比特组 [英] Breaking up a LPARAM variable & looking at groups of bits

查看:157
本文介绍了分手LPARAM可变的放大器;看着比特组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道一个LPARAM变量设置(里面)的某些位标识信息,如长按键presses&安培;等等。当我收到一个WM_KEYDOWN事件。

所以我想分手LPARAM可变的放大器;看个人位值放的群体;位和放大器组;该值(如看16日至24日比特及从该值)。

我的问题:我不知道如何来看待各个位和放大器;比特组?我如何分手的LPARAM变量和放大器;看位值(打印出来以二进制,十六进制和放大器;十进制)。

我有这到目前为止,但在比特级工作混淆了我很多,所以我不能确定,如果我真的很期待在24日,25日和放大器;十进制和放大器16位值;等等。

  LRESULT CALLBACK的WndProc(HWND HWND,UINT MSG,WPARAM wParam参数,LPARAM lParam的)
{    开关(MSG)
    {
        案例WM_KEYDOWN:
        {
            //我知道一个LPARAM变量是一个32位(或者是字节?)长变量。我将如何看
            // 16位的值?我怎么会看,从16日至24日位的价值?
            的printf(A:%D,%D,%d个\\ N,lParam的>> 24,lParam的>> 25,lParam的>> 16);
        }
        打破;


解决方案

在一般情况下,您使用按位与检查,如果某个位设置:

  unsigned int类型的标志; //一些标志如果(旗&安培; 0×01){} // 0位
如果(标志&放大器; 0×02){} //位1被置
如果(旗&安培; 0×04){} // 2位中
...
如果(标志及(1U&所述;&所述; n))的{} //位n被设置

不过,不依赖于物理位值。相反,API定义描述该标志的含义USEFUL_CONSTANTS:

  LPARAM标志= ApiFunction();
如果(标志&放大器; USEFUL_CONSTANT){} //检查是否设置了标志

检查相关信息的API文档,找出这些定义的值。

更新:我看到你的情况,你可能会真正想要的的,而不仅仅是标志。因此,要获得最低的16位的值,你只要按位与具有相应的位掩码值: unsigned int类型REPEAT_COUNT =标志和放大器; 0xFFFF的; 注意0xFFFF的是二进制1111111111111111

I know that a LPARAM variable has certain bits set(inside it) that identify information such as long key presses & etc. when I receive a WM_KEYDOWN event.

So I am trying to break up a LPARAM variable & look at groups of individual bit values & groups of bits & that value(for eg looking at the 16th to the 24th bit & the value from that).

My Problem: I dont know how to look at individual bits & groups of bits? How do I break up the LPARAM variable & look at bit values (printing it out in binary, hex & decimal).

I have this so far, but working at the bit level confuses me alot, so I am unsure if I am really looking at the 24th, 25th & 16th bit value in decimal & etc.

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

    switch(msg)
    {
        case WM_KEYDOWN:
        {
            // I know that a LPARAM variable is a 32 bit(or is it byte?) long variable. How would I look at the
            // 16th bit value? How would I look that the value from the 16th to the 24th bit?
            printf("A: %d, %d, %d\n", lParam >> 24, lParam >> 25, lParam >> 16 );
        }
        break;

解决方案

In general, you use bitwise-AND to check if a certain bit is set:

unsigned int flags;  // some flags

if (flags & 0x01) { } // bit 0 is set
if (flags & 0x02) { } // bit 1 is set
if (flags & 0x04) { } // bit 2 is set
...
if (flags & (1U << n)) { } // bit n is set

However, don't rely on the physical bit values. Instead, the API defines USEFUL_CONSTANTS that describe the meaning of the flags:

LPARAM flags = ApiFunction();
if (flags & USEFUL_CONSTANT) { } // check if the flag is set

Check the API documentation of the relevant message to find out which values are defined.

Update: I see that in your case you might actually want values rather than just flags. So, to get the value of the lowest 16 bits, you just bitwise-AND the value with the corresponding bitmask: unsigned int repeat_count = flags & 0xFFFF; Note that 0xFFFF is 1111111111111111 in binary.

这篇关于分手LPARAM可变的放大器;看着比特组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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