HOTKEY.CPP 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // HotKey.cpp: implementation of the CHotKey class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "gen_hotkeys.h"
  5. #include "HotKey.h"
  6. //////////////////////////////////////////////////////////////////////
  7. // Registration / Unregstration
  8. //////////////////////////////////////////////////////////////////////
  9. int RegisterHotkey(HOTKEY *hk)
  10. {
  11. if (!hk) return 1;
  12. wchar_t atomName[1024] = {0};
  13. bool unicode = 0;
  14. char* name = GetCommandName(hk->hkd.iCommand, &unicode);
  15. StringCchPrintfW(atomName, 1024, (unicode?L"%s %X %X %X":L"%hs %X %X %X"), name, hk->hkd.dwHotKey, hk->hkd.iCommand, GetTickCount());
  16. hk->atom = GlobalAddAtomW(atomName);
  17. if (!hk->atom)
  18. return 1;
  19. return !RegisterHotKey(psPlugin.hwndParent, hk->atom, GetModKeys(hk->hkd.dwHotKey), LOBYTE(hk->hkd.dwHotKey));
  20. }
  21. void UnregisterHotkey(HOTKEY *hk)
  22. {
  23. if (!hk || !hk->atom)
  24. return;
  25. UnregisterHotKey(psPlugin.hwndParent, hk->atom);
  26. GlobalDeleteAtom(hk->atom);
  27. hk->atom = NULL;
  28. }
  29. //////////////////////////////////////////////////////////////////////
  30. // Set / Get
  31. //////////////////////////////////////////////////////////////////////
  32. UINT GetModKeys(DWORD dwHotKey)
  33. {
  34. UINT result = 0;
  35. WORD wHotKey = HIBYTE(dwHotKey);
  36. if (wHotKey & HOTKEYF_ALT)
  37. result |= MOD_ALT;
  38. if (wHotKey & HOTKEYF_CONTROL)
  39. result |= MOD_CONTROL;
  40. if (wHotKey & HOTKEYF_WIN)
  41. result |= MOD_WIN;
  42. if (wHotKey & HOTKEYF_SHIFT)
  43. result |= MOD_SHIFT;
  44. return result;
  45. }