通过对 PreTranslateMessage(MSG* pMsg)函数的控制 不需要 去 繁琐的 重写 CEdit或 其他编辑控件的 OnKeyDown 方法 直接可以 在 绘制文字之前 截获 按键消息~! 简单实用~!
系统函数 BOOL CBuyItemDlg::PreTranslateMessage(MSG* pMsg)
{
_PreTranslateMessage( pMsg );
if( pMsg->message == WM_KEYDOWN)
{
CWnd *pWnd = GetFocus();
if( pWnd != NULL )
{
if( pWnd == GetDlgItem( IDC_BUY_EDIT ) )
{
//设置 不是数字键 不响应~!
if( pMsg->wParam < VK_NUMPAD0 || pMsg->wParam > VK_NUMPAD9)
{
return true;
}
}
}
}
return __super::PreTranslateMessage(pMsg);
}