aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/General/gen_hotkeys/HOTKEY.CPP
diff options
context:
space:
mode:
authorJean-Francois Mauguit <jfmauguit@mac.com>2024-09-24 09:03:25 -0400
committerGitHub <noreply@github.com>2024-09-24 09:03:25 -0400
commitbab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Plugins/General/gen_hotkeys/HOTKEY.CPP
parent4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff)
parent20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff)
downloadwinamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/Plugins/General/gen_hotkeys/HOTKEY.CPP')
-rw-r--r--Src/Plugins/General/gen_hotkeys/HOTKEY.CPP56
1 files changed, 56 insertions, 0 deletions
diff --git a/Src/Plugins/General/gen_hotkeys/HOTKEY.CPP b/Src/Plugins/General/gen_hotkeys/HOTKEY.CPP
new file mode 100644
index 00000000..ad6144dc
--- /dev/null
+++ b/Src/Plugins/General/gen_hotkeys/HOTKEY.CPP
@@ -0,0 +1,56 @@
+// HotKey.cpp: implementation of the CHotKey class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "gen_hotkeys.h"
+#include "HotKey.h"
+
+//////////////////////////////////////////////////////////////////////
+// Registration / Unregstration
+//////////////////////////////////////////////////////////////////////
+
+int RegisterHotkey(HOTKEY *hk)
+{
+ if (!hk) return 1;
+
+ wchar_t atomName[1024] = {0};
+ bool unicode = 0;
+ char* name = GetCommandName(hk->hkd.iCommand, &unicode);
+ StringCchPrintfW(atomName, 1024, (unicode?L"%s %X %X %X":L"%hs %X %X %X"), name, hk->hkd.dwHotKey, hk->hkd.iCommand, GetTickCount());
+ hk->atom = GlobalAddAtomW(atomName);
+ if (!hk->atom)
+ return 1;
+
+ return !RegisterHotKey(psPlugin.hwndParent, hk->atom, GetModKeys(hk->hkd.dwHotKey), LOBYTE(hk->hkd.dwHotKey));
+}
+
+void UnregisterHotkey(HOTKEY *hk)
+{
+ if (!hk || !hk->atom)
+ return;
+
+ UnregisterHotKey(psPlugin.hwndParent, hk->atom);
+ GlobalDeleteAtom(hk->atom);
+ hk->atom = NULL;
+}
+
+//////////////////////////////////////////////////////////////////////
+// Set / Get
+//////////////////////////////////////////////////////////////////////
+
+UINT GetModKeys(DWORD dwHotKey)
+{
+ UINT result = 0;
+ WORD wHotKey = HIBYTE(dwHotKey);
+
+ if (wHotKey & HOTKEYF_ALT)
+ result |= MOD_ALT;
+ if (wHotKey & HOTKEYF_CONTROL)
+ result |= MOD_CONTROL;
+ if (wHotKey & HOTKEYF_WIN)
+ result |= MOD_WIN;
+ if (wHotKey & HOTKEYF_SHIFT)
+ result |= MOD_SHIFT;
+
+ return result;
+} \ No newline at end of file