BOOL CFinanceDlg::PreTranslateMessage(MSG* pMsg) 
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'Q'&& (GetKeyState(VK_CONTROL)&0x8000))
{
MessageBox("CONTROL+Q");
}
//
return CDialog::PreTranslateMessage(pMsg);
}
-----------------------------------------------------
如果不加0x8000上去,就会出现BUG
如下的BUG:
第一次CTRL+Q,正常
第二次CTRL+Q,正常
从第三次开始,只要按下Q,无需按下CTRL,也照样能MessageBox("CONTROL+Q")这是为什么??????????谢谢

解决方案 »

  1.   

    同1楼问,为什么要去掉0x8000?getkeystate本来就是那么用的。 
      

  2.   

    去掉&& (GetKeyState(VK_CONTROL)&0x8000)就成了
    if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'Q') 
    那只要是Q按下都会弹MessageBox了
    所以你说的
    第一次CTRL+Q,正常
    第二次CTRL+Q,正常
    从第三次开始,只要按下Q,无需按下CTRL,也照样能MessageBox("CONTROL+Q") 
    很正常
    即使第一次第二次你不CTRL+Q,只按下Q,也会MessageBox("CONTROL+Q") 啊
      

  3.   

    GetKeyState Return Value:
    If the high-order bit is 1, the key is down; otherwise, it is up.
    0x8000 = 0b1000000000000000
      

  4.   

    看MSDN上的GetKeyState函数的说明