BOOL CtestDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
if(pMsg->message==WM_SYSKEYDOWN)//Alt+?系列热键
{
char keyMap[50]="";
BOOL bAlt=::GetKeyState(VK_MENU)&0x8000;
if(bAlt)
{
if(pMsg->wParam==VK_F4)//屏蔽Alt+F4
return true;
else if(((pMsg->wParam>=0x30)&&(pMsg->wParam<=0x39))||((pMsg->wParam>=0x41)&&(pMsg->wParam<=0x5a)))//Alt+?热键(?在0-9,A-Z)
{
sprintf(keyMap,"Alt+%c",pMsg->wParam);
GetDlgItem(IDC_EDIT)->SetWindowTextA(keyMap);
}
else
GetDlgItem(IDC_EDIT)->SetWindowTextA("无");
}
else
GetDlgItem(IDC_EDIT)->SetWindowTextA("无");
}
else if(pMsg->message==WM_KEYDOWN)
{
BOOL bCtrl=::GetKeyState(VK_CONTROL)&0x8000;
BOOL bShift=::GetKeyState(VK_SHIFT)&0x8000;
BOOL bAlt=::GetKeyState(VK_MENU)&0x8000;
BOOL bHotKey=bCtrl|bShift|bAlt;//判断是否有热键按下
char keyMap[50]="";
if(pMsg->wParam==VK_RETURN)//屏蔽回车
return true;
else if(pMsg->wParam==VK_ESCAPE)//屏蔽ESC
return true;
else if(bHotKey)
{
if(((pMsg->wParam>=0x30)&&(pMsg->wParam<=0x39))||((pMsg->wParam>=0x41)&&(pMsg->wParam<=0x5a)))
{
if(bCtrl)
sprintf(keyMap,"%sCtrl+",keyMap);
if(bShift)
sprintf(keyMap,"%sShift+",keyMap);
if(bAlt)
sprintf(keyMap,"%sAlt+",keyMap);
sprintf(keyMap,"%s%c",keyMap,pMsg->wParam);
GetDlgItem(IDC_EDIT)->SetWindowTextA(keyMap);
}
else
GetDlgItem(IDC_EDIT)->SetWindowTextA("无");
}
else
GetDlgItem(IDC_EDIT)->SetWindowTextA("无");
}
return CDialog::PreTranslateMessage(pMsg);
}