PreTranslateMessage,就看看英文单词就可以理解是干什么的了,Pre(Previous 之前的),Translate(转换),message(消息)---什么 什么的 之前转换消息。就是在把消息发送给windows应用程序之前转换成你想处理的,比如说屏蔽所有的按键消息(WM_CHAR),这些键盘的ASCII码都要经过DispatchMessage派送给系统的应用程序。以下是评比键盘消息的一个简单的应用,代码如下:
BOOL 类名::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
CString m_OfferPrice;
GetWindowText(m_OfferPrice);
if (pMsg->message==WM_CHAR)
{
if ((pMsg->wParam<7)||(pMsg->wParam>57)||(pMsg->wParam>8&&pMsg->wParam<45/*&&pMsg->wParam!=43*/)||( pMsg->wParam==45)||(pMsg->wParam==47)) //屏蔽所有的字符键
return TRUE;
}
return CEdit::PreTranslateMessage(pMsg);
}
本文介绍了PreTranslateMessage函数的使用方法,该函数可以在Windows应用程序接收到消息前对其进行转换或过滤。文章提供了一个具体的代码示例,展示了如何通过PreTranslateMessage屏蔽特定的键盘输入,例如阻止ASCII码不在数字范围内的字符键。
414

被折叠的 条评论
为什么被折叠?



