dlg2.cpp
资源名称:WarH_2.10.rar [点击查看]
上传用户:tree100901
上传日期:2016-07-12
资源大小:182k
文件大小:6k
源码类别:
外挂编程
开发平台:
Visual C++
- // dlg2.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "WarH.h"
- #include "MyEdit.h"
- #include "dlg2.h"
- CDlg2* g_pDlg2;
- HHOOK g_hKeyboard;
- BOOL bClipCursor = TRUE;
- void InitHOOK();
- // CDlg2 对话框
- IMPLEMENT_DYNAMIC(CDlg2, CDialog)
- CDlg2::CDlg2(CWnd* pParent /*=NULL*/)
- : CDialog(CDlg2::IDD, pParent)
- {
- }
- CDlg2::~CDlg2()
- {
- }
- void CDlg2::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_KEY7, m_Key7);
- DDX_Control(pDX, IDC_KEY8, m_Key8);
- DDX_Control(pDX, IDC_KEY4, m_Key4);
- DDX_Control(pDX, IDC_KEY5, m_Key5);
- DDX_Control(pDX, IDC_KEY1, m_Key1);
- DDX_Control(pDX, IDC_KEY2, m_Key2);
- DDX_Control(pDX, IDC_KEY10, m_Key10);
- DDX_Control(pDX, IDC_KEY11, m_Key11);
- DDX_Control(pDX, IDC_KEY20, m_Key20);
- DDX_Control(pDX, IDC_KEY21, m_Key21);
- DDX_Control(pDX, IDC_KEY30, m_Key30);
- DDX_Control(pDX, IDC_KEY31, m_Key31);
- DDX_Control(pDX, IDC_KEY40, m_Key40);
- DDX_Control(pDX, IDC_KEY41, m_Key41);
- DDX_Control(pDX, IDC_KEY50, m_Key50);
- DDX_Control(pDX, IDC_KEY51, m_Key51);
- }
- BEGIN_MESSAGE_MAP(CDlg2, CDialog)
- ON_BN_CLICKED(IDC_SAVE1, &CDlg2::OnBnClickedSave1)
- ON_BN_CLICKED(IDC_READ2, &CDlg2::OnBnClickedRead2)
- ON_WM_CTLCOLOR()
- END_MESSAGE_MAP()
- // CDlg2 消息处理程序
- BOOL CDlg2::OnInitDialog()
- {
- BOOL bResult = CDialog::OnInitDialog();
- ::SendMessage(m_Key1.m_hWnd, WM_INIT, 97, 0);
- ::SendMessage(m_Key2.m_hWnd, WM_INIT, 98, 0);
- ::SendMessage(m_Key4.m_hWnd, WM_INIT, 100, 0);
- ::SendMessage(m_Key5.m_hWnd, WM_INIT, 101, 0);
- ::SendMessage(m_Key7.m_hWnd, WM_INIT, 103, 0);
- ::SendMessage(m_Key8.m_hWnd, WM_INIT, 104, 0);
- ::SendMessage(m_Key11.m_hWnd, WM_INIT, 0, (LPARAM)m_Key10.m_hWnd);
- ::SendMessage(m_Key21.m_hWnd, WM_INIT, 0, (LPARAM)m_Key20.m_hWnd);
- ::SendMessage(m_Key31.m_hWnd, WM_INIT, 0, (LPARAM)m_Key30.m_hWnd);
- ::SendMessage(m_Key41.m_hWnd, WM_INIT, 0, (LPARAM)m_Key40.m_hWnd);
- ::SendMessage(m_Key51.m_hWnd, WM_INIT, 0, (LPARAM)m_Key50.m_hWnd);
- ::SendMessage(m_Key10.m_hWnd, WM_INIT, 0, 0);
- ::SendMessage(m_Key20.m_hWnd, WM_INIT, 0, 0);
- ::SendMessage(m_Key30.m_hWnd, WM_INIT, 0, 0);
- ::SendMessage(m_Key40.m_hWnd, WM_INIT, 0, 0);
- ::SendMessage(m_Key50.m_hWnd, WM_INIT, 0, 0);
- OnBnClickedRead2();
- g_pDlg2 = this;
- InitHOOK();
- return bResult;
- }
- void CDlg2::OnBnClickedSave1()
- {
- // TODO: 在此添加控件通知处理程序代码
- m_Key1.SaveKey(1);
- m_Key2.SaveKey(2);
- m_Key4.SaveKey(4);
- m_Key5.SaveKey(5);
- m_Key7.SaveKey(7);
- m_Key8.SaveKey(8);
- m_Key11.SaveKey(11);
- m_Key21.SaveKey(21);
- m_Key31.SaveKey(31);
- m_Key41.SaveKey(41);
- m_Key51.SaveKey(51);
- MessageBox(_T("保存成功!"), _T("Message: o(∩_∩)o"), MB_OK);
- }
- void CDlg2::OnBnClickedRead2()
- {
- // TODO: 在此添加控件通知处理程序代码
- m_Key1.ReadKey(1);
- m_Key2.ReadKey(2);
- m_Key4.ReadKey(4);
- m_Key5.ReadKey(5);
- m_Key7.ReadKey(7);
- m_Key8.ReadKey(8);
- m_Key11.ReadKey(11);
- m_Key21.ReadKey(21);
- m_Key31.ReadKey(31);
- m_Key41.ReadKey(41);
- m_Key51.ReadKey(51);
- }
- HBRUSH CDlg2::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- // TODO: 在此更改 DC 的任何属性
- int nID = pWnd->GetDlgCtrlID();
- switch (nID)
- {
- case IDC_STATIC0:
- pDC->SetTextColor(RGB(0, 0, 255));
- break;
- default:
- pDC->SetTextColor(RGB(255, 0, 0));
- }
- // TODO: 如果默认的不是所需画笔,则返回另一个画笔
- return hbr;
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void EnableEdits(BOOL bEnable)
- {
- g_pDlg2->m_Key1.EnableWindow(bEnable);
- g_pDlg2->m_Key2.EnableWindow(bEnable);
- g_pDlg2->m_Key4.EnableWindow(bEnable);
- g_pDlg2->m_Key5.EnableWindow(bEnable);
- g_pDlg2->m_Key7.EnableWindow(bEnable);
- g_pDlg2->m_Key8.EnableWindow(bEnable);
- g_pDlg2->m_Key10.EnableWindow(bEnable);
- g_pDlg2->m_Key11.EnableWindow(bEnable);
- g_pDlg2->m_Key20.EnableWindow(bEnable);
- g_pDlg2->m_Key21.EnableWindow(bEnable);
- g_pDlg2->m_Key30.EnableWindow(bEnable);
- g_pDlg2->m_Key31.EnableWindow(bEnable);
- g_pDlg2->m_Key40.EnableWindow(bEnable);
- g_pDlg2->m_Key41.EnableWindow(bEnable);
- g_pDlg2->m_Key50.EnableWindow(bEnable);
- g_pDlg2->m_Key51.EnableWindow(bEnable);
- }
- LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
- {
- PKBDLLHOOKSTRUCT pKey;
- pKey = (PKBDLLHOOKSTRUCT)lParam;//初始化对象
- switch(nCode)
- {
- case HC_ACTION:
- switch (wParam)
- {
- case WM_SYSKEYDOWN:
- switch (pKey->vkCode)
- {
- case VK_RMENU:
- if (theApp.m_bShowHP)
- {
- keybd_event(0xDB, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
- keybd_event(0xDD, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
- }
- else
- {
- keybd_event(0xDB, 0, KEYEVENTF_EXTENDEDKEY, 0);
- keybd_event(0xDD, 0, KEYEVENTF_EXTENDEDKEY, 0);
- }
- theApp.m_bShowHP = !theApp.m_bShowHP;
- break;
- }
- case WM_KEYDOWN:
- switch (pKey->vkCode)
- {
- case VK_DIVIDE:
- theApp.m_bChangeKey = !theApp.m_bChangeKey;
- EnableEdits(!theApp.m_bChangeKey );
- break;
- case VK_MULTIPLY:
- if (theApp.m_bActive)
- {
- HWND hWnd=::GetForegroundWindow();
- if (bClipCursor)
- {
- bClipCursor = 0;
- CRect r;
- CRect c;
- ::GetWindowRect(hWnd, &r);
- ::GetClientRect(hWnd, &c);
- CRect Clip;
- Clip.right = r.right - 4;
- Clip.bottom = r.bottom - 4;
- Clip.top = r.bottom - ( c.bottom - c.top ) - 3;
- Clip.left = r.right - ( c.right - c.left ) - 3;
- ::ClipCursor(&Clip);
- }
- else
- {
- bClipCursor = 1;
- ::ClipCursor(NULL);
- }
- }
- break;
- }
- case WM_KEYUP:
- case WM_SYSKEYUP:
- if (pKey->vkCode == VK_LWIN)//屏蔽win键
- {
- return TRUE;
- }
- break;
- }
- }
- return CallNextHookEx(g_hKeyboard, nCode, wParam, lParam);//传给系统继续处理
- }
- //初始化钩子
- void InitHOOK()
- {
- g_hKeyboard = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, (HINSTANCE)0x00400000, 0);//安装钩子
- }
- //卸载钩子
- void StopHOOK()
- {
- UnhookWindowsHookEx(g_hKeyboard);//卸载钩子
- }