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