Accels.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "stdafx.h"
  2. #include "Accels.h"
  3. CAccels::CAccels(){
  4. }
  5. void CAccels::AddAccel(CAccel &a)
  6. {
  7. m_Map.SetAt(a.Key, a.Cmd);
  8. }
  9. bool CAccels::OnMsg(MSG *pMsg, DWORD &dID)
  10. {
  11. // bit 30 (0x40000000) is 1 if this is NOT the first msg of the key
  12. // i.e. auto-repeat may cause multiple msgs of the same key
  13. if((pMsg->lParam &0x40000000) || (pMsg->message != WM_KEYDOWN && pMsg->message != WM_SYSKEYDOWN))
  14. {
  15. return NULL;
  16. }
  17. if(!pMsg || m_Map.GetCount() <= 0)
  18. {
  19. return NULL;
  20. }
  21. BYTE vkey = LOBYTE(pMsg->wParam);
  22. BYTE mod = GetKeyStateModifiers();
  23. DWORD key = ACCEL_MAKEKEY(vkey, mod);
  24. CString cs;
  25. cs.Format(_T("Key: %d, Mod: %d, vkey: %d"), key, mod, vkey);
  26. OutputDebugString(cs);
  27. if(m_Map.Lookup(key, dID))
  28. {
  29. return true;
  30. }
  31. return false;
  32. }
  33. BYTE CAccels::GetKeyStateModifiers()
  34. {
  35. BYTE m = 0;
  36. if(GetKeyState(VK_SHIFT) &0x8000)
  37. {
  38. m |= HOTKEYF_SHIFT;
  39. }
  40. if(GetKeyState(VK_CONTROL) &0x8000)
  41. {
  42. m |= HOTKEYF_CONTROL;
  43. }
  44. if(GetKeyState(VK_MENU) &0x8000)
  45. {
  46. m |= HOTKEYF_ALT;
  47. }
  48. if(GetKeyState(VK_LWIN) &0x8000)
  49. {
  50. m |= HOTKEYF_EXT;
  51. }
  52. if(GetKeyState(VK_RWIN) &0x8000)
  53. {
  54. m |= HOTKEYF_EXT;
  55. }
  56. return m;
  57. }