Breaking up a LPARAM variable & looking at groups of bits

前端 未结 4 1952
死守一世寂寞
死守一世寂寞 2021-01-16 23:52

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 a

4条回答
  •  隐瞒了意图╮
    2021-01-17 00:35

    LPARAM can hold a pointer value, this is important for 64-bit compatibility.

    To examine the nth bit (0 is least significant):

    if (lParam & (1 << n)) { /*bit set*/ } else { /* bit not set*/ }

    To extract it as either 0 or 1:

    (lParam >> n) & 1

    To extract X bits from position Y:

    (lParam >> Y) & ((1<

    This works by first shifting the bytes down to the least significant places and creates a X bit wide mask to mask them out.

提交回复
热议问题