Accels.cpp 1.3 KB

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