重载PreTranslateMessage函数
实现PreTranslateMessage(MSG* pMsg)
代码如下
BOOL CKeyTestDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message == WM_KEYDOWN)// 按键按下 { CString tmp; tmp.Format(L"KeyCode:%#x. key: ", pMsg->wParam); BOOL isExit = FALSE; BOOL isDoChange = TRUE; CString str = L""; if(pMsg->wParam == VK_BACK) str = L"退格"; else if(pMsg->wParam == VK_RETURN) {str = L"回车"; isExit = TRUE;} else if(pMsg->wParam == VK_SCAN) str = L"扫描键"; else if(pMsg->wParam == VK_ESCAPE){ str = L"ESC"; isExit = TRUE; } else if(pMsg->wParam == VK_SPACE) str = L"空格键"; else if(pMsg->wParam == VK_LEFT) str = L"向左"; else if(pMsg->wParam == VK_UP) str = L"向上"; else if(pMsg->wParam == VK_RIGHT) str = L"向右"; else if(pMsg->wParam == VK_DOWN) str = L"向下"; else if(pMsg->wParam == VK_DELETE) str = L"删除"; else if(pMsg->wParam == VK_TSTAR && GetKeyState(VK_SHIFT)<0){ str += L"*"; } else if(pMsg->wParam == VK_TPOUND && GetKeyState(VK_SHIFT)<0){ str += L"#"; } else if(pMsg->wParam>=VK_T0 && pMsg->wParam<=VK_T9){ str.Format(L"%d", pMsg->wParam-VK_T0); } else if(pMsg->wParam == VK_F1) str = L"F1"; else if(pMsg->wParam == VK_TEND) str = L"挂机键"; else if(pMsg->wParam == VK_TTALK) str = L"通话键"; else{ isDoChange = FALSE; } mEdit.SetWindowTextW(tmp + str); if(isDoChange){ /*SetPowerRequirement(TEXT("BKL1:"), D1, POWER_NAME, NULL, 0); HANDLE bklEvent = CreateEvent(NULL, false, false, L"BackLightChangeEvent"); if(bklEvent != NULL){ SetEvent(bklEvent); CloseHandle(bklEvent); } const TCHAR szevtUserInput[] = TEXT("PowerManager/ActivityTimer/UserActivity"); HANDLE bklEvent = CreateEvent(NULL, false, false, szevtUserInput); if(bklEvent != NULL){ SetEvent(bklEvent); CloseHandle(bklEvent); }*/ } if(isExit) return TRUE; } return CDialog::PreTranslateMessage(pMsg); }
//******************************************************************** //***********************【SOF】 按键键值 **************************** #define VK_BACK 0x08 // 退格 #define VK_RETURN 0x0D // 回车 #define VK_SCAN 0x0E // 扫描键 #define VK_ESCAPE 0x1B // ESC #define VK_SPACE 0x20 // 空格键 #define VK_LEFT 0x25 // 向左 #define VK_UP 0x26 // 向上 #define VK_RIGHT 0x27 // 向右 #define VK_DOWN 0x28 // 向下 #define VK_DELETE 0x2E // 删除 #define VK_T0 0x30 // 0 #define VK_T1 0x31 // 1 #define VK_T2 0x32 // 2 #define VK_T3 0x33 // 3 #define VK_T4 0x34 // 4 #define VK_T5 0x35 // 5 #define VK_T6 0x36 // 6 #define VK_T7 0x37 // 7 #define VK_T8 0x38 // 8 #define VK_T9 0x39 // 9 #define VK_TSTAR 0x38 // *(shift+8组合键) #define VK_TPOUND 0x33 // #(shift+3组合键) #define VK_F1 0x70 // F1 #define VK_TEND 0x73 // 挂机键 #define VK_TTALK 0x72 // 拨号键/接听键 //***********************【EOF】 按键键值 **************************** //********************************************************************
http://download.csdn.net/detail/thanklife/7010095