MyEdit.cpp
资源名称:WarH_2.10.rar [点击查看]
上传用户:tree100901
上传日期:2016-07-12
资源大小:182k
文件大小:4k
源码类别:
外挂编程
开发平台:
Visual C++
- // MyEdit.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "WarH.h"
- #include "MyEdit.h"
- #include "Register.h"
- // CMyEdit
- IMPLEMENT_DYNAMIC(CMyEdit, CEdit)
- CMyEdit::CMyEdit()
- {
- m_DeshWnd = NULL;
- m_cVKcharSrc = NULL;
- m_cVKcharDes = NULL;
- }
- CMyEdit::~CMyEdit()
- {
- }
- BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
- ON_WM_KEYDOWN()
- END_MESSAGE_MAP()
- // CMyEdit 消息处理程序
- BOOL CMyEdit::SaveKey(int index)
- {
- CRegister reg;
- BOOL bResult = TRUE;
- char buf[] = "0key";
- buf[0] = char(index);
- DWORD dwKey = m_cVKcharSrc | (m_cVKcharDes << 16);
- bResult = bResult && reg.CreateKeyW(HKEY_CURRENT_USER, _T("Software\Blizzard Entertainment\Warcraft III\WarH"));
- bResult = bResult && reg.SetValueExExA(buf, REG_BINARY, (LPBYTE)&dwKey, sizeof(DWORD));
- return bResult;
- }
- BOOL CMyEdit::ReadKey(int index)
- {
- CRegister reg;
- BOOL bResult = TRUE;
- char buf[] = "0key";
- buf[0] = char(index);
- DWORD dwKey;
- bResult = bResult && reg.CreateKeyW(HKEY_CURRENT_USER, _T("Software\Blizzard Entertainment\Warcraft III\WarH"));
- bResult = bResult && reg.QueryValueExA(buf, (LPBYTE)&dwKey, 4);
- if (bResult)
- {
- m_cVKcharSrc = dwKey & 0x000000FF;
- m_cVKcharDes = (dwKey & 0x00FF0000) >> 16;
- if (m_cVKcharSrc && m_cVKcharDes)
- {
- if (m_DeshWnd)
- {
- ::SendMessage(m_hWnd, WM_KEYDOWN, m_cVKcharSrc, 0);
- ::SendMessage(m_DeshWnd, WM_KEYDOWN, m_cVKcharDes, 0);
- }
- else
- {
- ::SendMessage(m_hWnd, WM_KEYDOWN, m_cVKcharDes, 0);
- }
- }
- }
- return bResult;
- }
- LRESULT CMyEdit::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- CHAR buf[4] = "0键";
- switch (message)
- {
- case WM_INIT:
- m_cVKcharSrc = (UCHAR)wParam;
- m_DeshWnd = (HWND)lParam;
- SetWindowText(_T("<无>"));
- break;
- case WM_CHAR:
- break;
- case WM_KEYDOWN:
- if (wParam == VK_BACK)
- {
- SetWindowText(_T("<无>"));
- if (m_DeshWnd)
- {
- ::PostMessage(m_DeshWnd, WM_SETSRC, 0, 0);
- }
- else
- {
- ::PostMessage(m_hWnd, WM_SETDES, 0, 0);
- }
- }
- else if('A' <= wParam && wParam <= 'Z' || '0' <= wParam && wParam <= '9')
- {
- if (m_DeshWnd)
- {
- ::PostMessage(m_DeshWnd, WM_SETSRC, wParam, 0);
- }
- else
- {
- ::PostMessage(m_hWnd, WM_SETDES, wParam, 0);
- }
- buf[0] = wParam;
- SetWindowTextA(m_hWnd, buf);
- }
- break;
- case WM_SETSRC:
- if (m_cVKcharDes)
- {
- ::UnregisterHotKey(m_hWnd, m_cVKcharDes);
- }
- m_cVKcharSrc = (UCHAR)wParam;
- PostMessage(WM_SETHOT, m_cVKcharSrc, m_cVKcharDes);
- break;
- case WM_SETDES:
- if (m_cVKcharDes)
- {
- ::UnregisterHotKey(m_hWnd, m_cVKcharDes);
- }
- m_cVKcharDes = (UCHAR)wParam;
- PostMessage(WM_SETHOT, m_cVKcharSrc, m_cVKcharDes);
- break;
- case WM_SETHOT:
- if (m_cVKcharDes)
- {
- ::UnregisterHotKey(m_hWnd, m_cVKcharDes);
- }
- if (wParam && lParam)
- {
- m_cVKcharSrc = (UCHAR)wParam;
- m_cVKcharDes = (UCHAR)lParam;
- ::RegisterHotKey(m_hWnd, m_cVKcharDes, 0, m_cVKcharDes);
- }
- break;
- case WM_HOTKEY:
- if (!theApp.m_bInput && theApp.m_bActive && theApp.m_bChangeKey)
- {
- keybd_event(m_cVKcharSrc, 0, KEYEVENTF_EXTENDEDKEY, 0);
- keybd_event(m_cVKcharSrc, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
- }
- else
- {
- ::UnregisterHotKey(m_hWnd, m_cVKcharDes);
- keybd_event(m_cVKcharDes, 0, KEYEVENTF_EXTENDEDKEY, 0);
- keybd_event(m_cVKcharDes, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
- ::RegisterHotKey(m_hWnd, m_cVKcharDes, 0, m_cVKcharDes);
- }
- break;
- default:
- return CWnd::DefWindowProc(message, wParam, lParam);
- }
- return 0;
- }