c++ - Building my own LPARAM variable -
i want create own lparam pass win32 function getkeynametext(), (the first parameter takes lparam var).
this may seem doing things hard way, work around not having specific amounts of information & working @ bit level confusing me why want familiarise myself this.
so want put in lparam var is: - set 16-23 bits keyboard scan code: i've got scan code dont know how combine 32bit variable? - set 24th bit extended-key flag (i have no idea how yet alone how combine 32 bit variable) - set 25th bit dont care bit care - set bit 1?
so understand way binary & bits work...i think, amazing understand higher lvl concepts polymorphism not lower lvl computer hardware stuff :p
so have 32 bit(or byte?) variable, mean have 32 0's & 1's: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx or have variable xxxxxx, eg 100011(which 35), last number 2^0(so 1), 2^1(2), 2^2(4), .... 2^5(32).
so create lparam this:
dword scancode = 0x??; // dword 32bit var, scan code 7 bits long? bit extflag = 1; // there bit variable? how can find out extended-key flag also? bit carebit = 1; //now combine this? dword mylparam = scancode & extflag & carebit; // or lparam mylparam = scancode & extflag & carebit;
i think best way use bitfields ( http://msdn.microsoft.com/en-us/library/ewwyfdbe%28v=vs.80%29.aspx )
heres structure use key state 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 implement 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; }
Comments
Post a Comment