[C++ ] MFC 中 另類的 控制編輯框 字符方法~!

通過對 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);
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章