VC下使CDialog响应键盘按键(Response of Key)
需要重载PreTranslateMessage函数
具体实现:
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
//按键相应
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);
}
Trackback from your site.