我想知道在程序运行中用户按下了哪个按钮,于是用PreTranslateMessage的方法,比如这样:
BOOL CP_View::PreTranslateMessage(MSG *pMsg)
{
if( pMsg->message == WM_KEYDOWN )
{
switch(pMsg->wParam)
{case 39://右方向键
break;
}
}
str.Format("%d",pMsg->wParam);
AfxMessageBox(str);
return true;
}
这样做确实可以回应按键动作,但是将导致一开始运行程序CPU就持续100%,那么有时候其他的事情就没办法处理了。
请大佬们解释一下原因,并告知解决方法。
BOOL CP_View::PreTranslateMessage(MSG *pMsg)
{
if( pMsg->message == WM_KEYDOWN )
{
switch(pMsg->wParam)
{case 39://右方向键
break;
}
}
str.Format("%d",pMsg->wParam);
AfxMessageBox(str);
return true;
}
这样做确实可以回应按键动作,但是将导致一开始运行程序CPU就持续100%,那么有时候其他的事情就没办法处理了。
请大佬们解释一下原因,并告知解决方法。
用OutputDebugString
{
//改键值
if (WM_KEYFIRST <= pMsg->message && pMsg->message <= WM_KEYLAST)
//只处理键盘输入
{
if(pMsg->wParam==VK_RETURN )//如果是回车
{
HWND hWnd=::GetFocus();
int iID=::GetDlgCtrlID(hWnd);
if(iID==IDC_EDIT1)//如果是在EDIT中回车
{
CString str;
GetDlgItemText(IDC_EDIT1,str);//结束EDIT输入
SetDlgItemText(IDC_STATIC1,str);
}
return true;
}
if(pMsg->wParam=='1' )pMsg->wParam='0';//改变按键1->0
}
return CDialog::PreTranslateMessage(pMsg);
}