建设自己的LPARAM变量 [英] Building my own LPARAM variable

查看:94
本文介绍了建设自己的LPARAM变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创造我自己的LPARAM传递到Win32函数GetKeyNameText(),(第一个参数需要一个LPARAM变量)。

这似乎是做事情了艰​​辛的道路,但其不具有信息和放大器具体数额变通;也在位一级的工作是让人有些困惑我这就是为什么我想这个熟悉自己。

所以,我希望把我的LPARAM VAR是什么:
- 在16-23位设置在键盘扫描code:我已经得到了扫描code我只是不知道我会如何合并成一个32位的变量?
- 设置第24位扩展键标志(我不知道怎么又遑论如何将其合并成一个32位变量得到这个)
- 第25位设置为不关心位我做护理? - 所以我会设置该位为1

所以我理解的方式二元放大器;位工作...我认为,其惊人的我明白了更高拉特的概念,如多态,但不会低拉特计算机硬件的东西:P

所以我有一个32位(?或字节)的变量,这意味着我有32个0&安培; 1的:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
要么
我有这样XXXXXX一个变量,例如100011(其为35),其中,最后的数字是2 ^ 0(因此1)中,然后用2 ^ 1(2),然后用2 ^ 2(4),...然后最后2 ^ 5(32)。

因此​​,要创建我LPARAM我会做到这一点:

  DWORD扫描code = 0X ??; //一个DWORD是一个32位的无功,但扫描code是只有7位长?
位extFlag = 1; //现在是有位变量?我怎样才能找出扩展键标志也?
位careBit = 1;//我们这一切我会做这种结合?
DWORD myLParam =扫描code&放; extFlag&安培; careBit;
// 要么
LPARAM myLParam =扫描code&放; extFlag&安培; careBit;


解决方案

我觉得要做到这一点的最好方法是使用位域(的 http://msdn.microsoft.com/en-us/library/ewwyfdbe%28v=vs.80%29.aspx

继承人我用它来从LPARAM获得国家重点的结构:

 工会KeyState
{
    LPARAM lParam的;    结构
    {
        无符号nRepeatCount:16;
        无符号nScan code:8;
        无符号nExtended:1;
        无符号nReserved:4;
        无符号nContext:1;
        无符号ñpreV:1;
        无符号nTrans:1;
    };
};

,那么只需在实现为:

  KeyState keyState; //全局声明
案例WM_KEYDOWN:
{
    keyState.lparam = LPARAM;    //这里使用的值,例如:
    的printf(%D,%D,%D,keyState.nRepeatCount,keyState.nScan code,keyState.nExtended);    返回0;
}

I want to create my own LPARAM to pass to the win32 function GetKeyNameText(), (the first parameter takes a LPARAM var).

This may seem like doing things the hard way, but its a work around for not having specific amounts of information & also working at the bit level is REALLY confusing to me which is why I want to familiarise myself with this.

So what I want to put in my LPARAM var is: - set the 16-23 bits to the keyboard Scan code: I've got the scan code I just dont know how I would combine it into a 32bit variable? - set the 24th bit to the extended-key flag (I have no idea how to get this yet alone how to combine it into a 32 bit variable) - set the 25th bit to the dont care bit to I do care - so would I set this bit to 1?

So I understand the way binary & bits work...I think, its amazing I understand higher lvl concepts like polymorphism but not lower lvl computer hardware stuff :P

So I have a 32 bit(or byte?) variable, does that mean I have 32 0's & 1's: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX OR I have a variable like this XXXXXX, eg 100011(which is 35), where the last number is 2^0(so 1), then 2^1(2), then 2^2(4), .... then finally 2^5(32).

So to create my LPARAM would I do this:

DWORD scanCode = 0x??;  // a DWORD is a 32bit var, but the scan code is only 7 bits long?
bit   extFlag       = 1;        // now is there a bit variable? How can I find out the extended-key flag also?
bit   careBit       = 1;       

//Now to combine it all would I do this? 
DWORD myLParam = scanCode & extFlag & careBit;
// OR
LPARAM myLParam = scanCode & extFlag & careBit;

解决方案

I think the best way to do this is to use bitfields ( http://msdn.microsoft.com/en-us/library/ewwyfdbe%28v=vs.80%29.aspx )

Heres a structure i use to get key state from a LPARAM:

union KeyState
{
    LPARAM lparam;

    struct
    {
        unsigned nRepeatCount : 16;
        unsigned nScanCode : 8;
        unsigned nExtended : 1;
        unsigned nReserved : 4;
        unsigned nContext : 1;
        unsigned nPrev : 1;
        unsigned nTrans : 1;
    };
};

Then you would implement it simply as:

KeyState keyState; // declared globally
case WM_KEYDOWN:
{
    keyState.lparam = lparam;

    // Use values here, e.g:
    printf("%d,%d,%d", keyState.nRepeatCount, keyState.nScanCode, keyState.nExtended);

    return 0;
}

这篇关于建设自己的LPARAM变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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