简体   繁体   中英

WM_CHAR lParam extended key (24 bit) always 0

I'm trying get extended key state

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 always == 0

I tried to turn out information in the different ways, like (lParam << 24) & 1;

all the same nExtended == 0

Win7 64 bit, Visual Studio 2010

The documentation for WM_CHAR says:

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.

You will have to process the WM_KEYDOWN and WM_KEYUP messages to get extended key information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM