[C++ ] MFC 中 另类的 控制编辑框 字符方法~!

来源:互联网 发布:阿里云服务器干嘛用的 编辑:程序博客网 时间:2024/05/17 03:46

通过对 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);
}

原创粉丝点击