c++ - WM_CHAR lParam 扩展 key (24 位)始终为 0

标签 c++ winapi bit-manipulation

我正在尝试获取扩展键状态

WNDPROC lpfnEditWndProc; 

//edit - hwnd of edit control
lpfnEditWndProc = (WNDPROC) SetWindowLong(edit, GWL_WNDPROC, (DWORD) SubClassProc); 


struct Bits {
    WORD nRepeatCount: 16;
    BYTE nScanCode : 8;
    BYTE nExtended : 1;
    BYTE nReserved : 4;
    BYTE nContext : 1;
    BYTE nPrevious : 1;
    BYTE nTransition : 1;
  };


union KeyInfo
{  
  LPARAM lParam;
  Bits bits;  
};


LRESULT CALLBACK SubClassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 
{
     switch (msg) { 
          case WM_CHAR: 
          {
              KeyInfo v;
              v.lParam = lParam;

              printf("nExtended = %d\n", v.bits.nExtended);
          }
          break;

     }

     return CallWindowProc(lpfnEditWndProc, hwnd, msg, wParam, lParam); 
}

nExtended 总是 == 0

我尝试以不同的方式获取信息,比如 (lParam << 24) & 1;

都一样 nExtended == 0

Win7 64 位,Visual Studio 2010

最佳答案

documentation for WM_CHAR说:

Because there is not necessarily a one-to-one correspondence between keys pressed and character messages generated, the information in the high-order word of the lParam parameter is generally not useful to applications. The information in the high-order word applies only to the most recent WM_KEYDOWN message that precedes the posting of the WM_CHAR message.

您必须处理 WM_KEYDOWN 和 WM_KEYUP 消息才能获得扩展 key 信息。

关于c++ - WM_CHAR lParam 扩展 key (24 位)始终为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10671526/

相关文章:

c++ - 模板化优先级队列导致对象成为指针。由 小码哥发布于

c++ - 多态智能指针的使用

C++ 在 win32 控制台中制作游戏

c++ - 用于打开资源文件并从中获取数据的 Win32 api

c++ - 拒绝访问注册表

c - 循环展开(按位运算)

c++ - 为什么 UuidFromString 函数请求非常量指针指向 unsigned char?

c++ - 我在使用 GetFullPathName 时遇到错误

SQL按位不(~)

C#反转整数的位