BOOL CSearchuserDlg::PreTranslateMessage(MSG* pMsg)

{

     if (pMsg->message==WM_KEYDOWN)  // 判断是否有按键按下

     {

           switch (pMsg->wParam)

           {

           case VK_DOWN:     // 表示是方向键中的向下的键

                //add handle code here

                break ;

           case VK_UP:      // 表示是方向键中的向上的键

                //add handle code here

                break ;

           default :

                break ;

           }

     }

}
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)

{
     // 按键相应
     if (pMsg->message == WM_KEYDOWN)
     {
           if (pMsg->wParam == VK_DOWN)
           {
                // 向下键按下
           }
           else if (pMsg->wParam == VK_RIGHT)
           {
                // 向右键按下
           }
           else if (pMsg->wParam == VK_LEFT)
          {
                // 向左键按下
           }
           else if (pMsg->wParam == VK_UP)
           {
                // 向上键按下
           }
           else if (pMsg->wParam == VK_SHIFT)
           {
                //VK_LSHIFT 为左 Shift 键按下
                //Shift 键按下
           }
           else if (pMsg->wParam == VK_CONTROL)
           {

                //Ctrl 键按下

           }

           else if (pMsg->wParam>=VK_NUMPAD0 && pMsg->wParam<=VK_NUMPAD9)

           {
                // 小键盘数字键按下

           }
           else if (pMsg->wParam>=0x30 && pMsg->wParam<=0x39)
           {
                // 数字键按下 ( 我记得不能使用 VK_0)
           }
           else if (pMsg->wParam>=0x41 && pMsg->wParam<=0x5A)
           {
                // 键盘字母键按下 ( 我记得不能使用 VK_A)
           }
           else if (pMsg->wParam == VK_BACK)

           {
                // 退格键按下
           }
           else if (pMsg->wParam == VK_DELETE)
           {
                // 删除键按下
           }
           else if (pMsg->wParam == VK_F1)
           {
                //F1 键按下
           }
           //return true;  // 使消息不再进行处理
     }

     if (pMsg->message == WM_KEYUP)
     {
           if (pMsg->wParam == VK_SHIFT)

           {
                //Shift 键弹起
           }
           else if (pMsg->wParam == VK_CONTROL)
           {
                //Ctrl 键弹起
           }
           //return true;  // 使消息不再进行处理
     }
     return CDialog::PreTranslateMessage(pMsg);
}

相关文章:

  • 2022-01-06
  • 2022-12-23
  • 2021-05-09
  • 2021-04-13
  • 2021-07-01
  • 2021-05-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2021-06-19
  • 2021-07-27
  • 2022-12-23
  • 2021-08-25
相关资源
相似解决方案