做windows開發有段時間了,但項目多數都不沒涉及到鍵盤事件的處理。現在用到突然忘了。
處理鍵盤可以通過兩種方式:
1. hook 技術偵測。 這裏就先不介紹,有機會在整理。
2. 通過重載PreTranslateMessage函數也可以實現。
BOOL CScanDemoDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加專用代碼和/或調用基類
if (pMsg->message == WM_KEYUP && (pMsg->wParam ==VK_SCAN_A||pMsg->wParam ==VK_SCAN_B ) )
{
//deal with the Scan function
RETAILMSG(1,(L"Start to Scan barcode \r\n"));
if(StartScan())
{
(CButton*)GetDlgItem(IDC_BTN_PRINT)->EnableWindow(TRUE);
}
else
(CButton*)GetDlgItem(IDC_BTN_PRINT)->EnableWindow(FALSE);
UpdateData(FALSE);
}
return CDialog::PreTranslateMessage(pMsg);
}