| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #include "stdafx.h"
- #include "Accels.h"
- #include "HotKeys.h"
- CAccels::CAccels(){
- }
- void CAccels::AddAccel(CAccel a)
- {
- m_Map.SetAt(a.Key, a);
- }
- void CAccels::AddAccel(DWORD cmd, DWORD key)
- {
- CAccel a;
- a.Cmd = cmd;
- a.Key = key;
- m_Map.SetAt(key, a);
- }
- void CAccels::RemoveAll()
- {
- m_Map.RemoveAll();
- }
- CString CAccels::GetCmdKeyText(DWORD cmd)
- {
- CString cmdShortcutText = _T("");
- POSITION pos = m_Map.GetStartPosition();
- DWORD mapShortcut;
- CAccel a;
- while (pos != NULL)
- {
- m_Map.GetNextAssoc(pos, mapShortcut, a);
- if(a.Cmd == cmd)
- {
- cmdShortcutText = CHotKey::GetHotKeyDisplayStatic(mapShortcut);
- break;
- }
- }
- return cmdShortcutText;
- }
- bool CAccels::OnMsg(MSG *pMsg, CAccel &a)
- {
- // bit 30 (0x40000000) is 1 if this is NOT the first msg of the key
- // i.e. auto-repeat may cause multiple msgs of the same key
- if((pMsg->lParam &0x40000000) || (pMsg->message != WM_KEYDOWN && pMsg->message != WM_SYSKEYDOWN))
- {
- return NULL;
- }
- if(!pMsg || m_Map.GetCount() <= 0)
- {
- return NULL;
- }
- BYTE vkey = LOBYTE(pMsg->wParam);
- BYTE mod = GetKeyStateModifiers();
- DWORD key = ACCEL_MAKEKEY(vkey, mod);
- CString cs;
- cs.Format(_T("Key: %d, Mod: %d, vkey: %d"), key, mod, vkey);
- OutputDebugString(cs);
- if(m_Map.Lookup(key, a))
- {
- return true;
- }
- return false;
- }
- BYTE CAccels::GetKeyStateModifiers()
- {
- BYTE m = 0;
- if(GetKeyState(VK_SHIFT) &0x8000)
- {
- m |= HOTKEYF_SHIFT;
- }
- if(GetKeyState(VK_CONTROL) &0x8000)
- {
- m |= HOTKEYF_CONTROL;
- }
- if(GetKeyState(VK_MENU) &0x8000)
- {
- m |= HOTKEYF_ALT;
- }
- if(GetKeyState(VK_LWIN) &0x8000)
- {
- m |= HOTKEYF_EXT;
- }
- if(GetKeyState(VK_RWIN) &0x8000)
- {
- m |= HOTKEYF_EXT;
- }
- return m;
- }
|