dlg2.cpp
上传用户:tree100901
上传日期:2016-07-12
资源大小:182k
文件大小:6k
源码类别:

外挂编程

开发平台:

Visual C++

  1. // dlg2.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "WarH.h"
  5. #include "MyEdit.h"
  6. #include "dlg2.h"
  7. CDlg2* g_pDlg2;
  8. HHOOK g_hKeyboard;
  9. BOOL bClipCursor = TRUE;
  10. void InitHOOK();
  11. // CDlg2 对话框
  12. IMPLEMENT_DYNAMIC(CDlg2, CDialog)
  13. CDlg2::CDlg2(CWnd* pParent /*=NULL*/)
  14. : CDialog(CDlg2::IDD, pParent)
  15. {
  16. }
  17. CDlg2::~CDlg2()
  18. {
  19. }
  20. void CDlg2::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange(pDX);
  23. DDX_Control(pDX, IDC_KEY7, m_Key7);
  24. DDX_Control(pDX, IDC_KEY8, m_Key8);
  25. DDX_Control(pDX, IDC_KEY4, m_Key4);
  26. DDX_Control(pDX, IDC_KEY5, m_Key5);
  27. DDX_Control(pDX, IDC_KEY1, m_Key1);
  28. DDX_Control(pDX, IDC_KEY2, m_Key2);
  29. DDX_Control(pDX, IDC_KEY10, m_Key10);
  30. DDX_Control(pDX, IDC_KEY11, m_Key11);
  31. DDX_Control(pDX, IDC_KEY20, m_Key20);
  32. DDX_Control(pDX, IDC_KEY21, m_Key21);
  33. DDX_Control(pDX, IDC_KEY30, m_Key30);
  34. DDX_Control(pDX, IDC_KEY31, m_Key31);
  35. DDX_Control(pDX, IDC_KEY40, m_Key40);
  36. DDX_Control(pDX, IDC_KEY41, m_Key41);
  37. DDX_Control(pDX, IDC_KEY50, m_Key50);
  38. DDX_Control(pDX, IDC_KEY51, m_Key51);
  39. }
  40. BEGIN_MESSAGE_MAP(CDlg2, CDialog)
  41. ON_BN_CLICKED(IDC_SAVE1, &CDlg2::OnBnClickedSave1)
  42. ON_BN_CLICKED(IDC_READ2, &CDlg2::OnBnClickedRead2)
  43. ON_WM_CTLCOLOR()
  44. END_MESSAGE_MAP()
  45. // CDlg2 消息处理程序
  46. BOOL CDlg2::OnInitDialog()
  47. {
  48. BOOL bResult = CDialog::OnInitDialog();
  49. ::SendMessage(m_Key1.m_hWnd, WM_INIT, 97, 0);
  50. ::SendMessage(m_Key2.m_hWnd, WM_INIT, 98, 0);
  51. ::SendMessage(m_Key4.m_hWnd, WM_INIT, 100, 0);
  52. ::SendMessage(m_Key5.m_hWnd, WM_INIT, 101, 0);
  53. ::SendMessage(m_Key7.m_hWnd, WM_INIT, 103, 0);
  54. ::SendMessage(m_Key8.m_hWnd, WM_INIT, 104, 0);
  55. ::SendMessage(m_Key11.m_hWnd, WM_INIT, 0, (LPARAM)m_Key10.m_hWnd);
  56. ::SendMessage(m_Key21.m_hWnd, WM_INIT, 0, (LPARAM)m_Key20.m_hWnd);
  57. ::SendMessage(m_Key31.m_hWnd, WM_INIT, 0, (LPARAM)m_Key30.m_hWnd);
  58. ::SendMessage(m_Key41.m_hWnd, WM_INIT, 0, (LPARAM)m_Key40.m_hWnd);
  59. ::SendMessage(m_Key51.m_hWnd, WM_INIT, 0, (LPARAM)m_Key50.m_hWnd);
  60. ::SendMessage(m_Key10.m_hWnd, WM_INIT, 0, 0);
  61. ::SendMessage(m_Key20.m_hWnd, WM_INIT, 0, 0);
  62. ::SendMessage(m_Key30.m_hWnd, WM_INIT, 0, 0);
  63. ::SendMessage(m_Key40.m_hWnd, WM_INIT, 0, 0);
  64. ::SendMessage(m_Key50.m_hWnd, WM_INIT, 0, 0);
  65. OnBnClickedRead2();
  66. g_pDlg2 = this;
  67. InitHOOK();
  68. return bResult;
  69. }
  70. void CDlg2::OnBnClickedSave1()
  71. {
  72. // TODO: 在此添加控件通知处理程序代码
  73. m_Key1.SaveKey(1);
  74. m_Key2.SaveKey(2);
  75. m_Key4.SaveKey(4);
  76. m_Key5.SaveKey(5);
  77. m_Key7.SaveKey(7);
  78. m_Key8.SaveKey(8);
  79. m_Key11.SaveKey(11);
  80. m_Key21.SaveKey(21);
  81. m_Key31.SaveKey(31);
  82. m_Key41.SaveKey(41);
  83. m_Key51.SaveKey(51);
  84. MessageBox(_T("保存成功!"), _T("Message: o(∩_∩)o"), MB_OK);
  85. }
  86. void CDlg2::OnBnClickedRead2()
  87. {
  88. // TODO: 在此添加控件通知处理程序代码
  89. m_Key1.ReadKey(1);
  90. m_Key2.ReadKey(2);
  91. m_Key4.ReadKey(4);
  92. m_Key5.ReadKey(5);
  93. m_Key7.ReadKey(7);
  94. m_Key8.ReadKey(8);
  95. m_Key11.ReadKey(11);
  96. m_Key21.ReadKey(21);
  97. m_Key31.ReadKey(31);
  98. m_Key41.ReadKey(41);
  99. m_Key51.ReadKey(51);
  100. }
  101. HBRUSH CDlg2::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  102. {
  103. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  104. // TODO:  在此更改 DC 的任何属性
  105. int nID = pWnd->GetDlgCtrlID();
  106. switch (nID)
  107. {
  108. case IDC_STATIC0:
  109. pDC->SetTextColor(RGB(0, 0, 255));
  110. break;
  111. default:
  112. pDC->SetTextColor(RGB(255, 0, 0));
  113. }
  114. // TODO:  如果默认的不是所需画笔,则返回另一个画笔
  115. return hbr;
  116. }
  117. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  118. void EnableEdits(BOOL bEnable)
  119. {
  120. g_pDlg2->m_Key1.EnableWindow(bEnable);
  121. g_pDlg2->m_Key2.EnableWindow(bEnable);
  122. g_pDlg2->m_Key4.EnableWindow(bEnable);
  123. g_pDlg2->m_Key5.EnableWindow(bEnable);
  124. g_pDlg2->m_Key7.EnableWindow(bEnable);
  125. g_pDlg2->m_Key8.EnableWindow(bEnable);
  126. g_pDlg2->m_Key10.EnableWindow(bEnable);
  127. g_pDlg2->m_Key11.EnableWindow(bEnable);
  128. g_pDlg2->m_Key20.EnableWindow(bEnable);
  129. g_pDlg2->m_Key21.EnableWindow(bEnable);
  130. g_pDlg2->m_Key30.EnableWindow(bEnable);
  131. g_pDlg2->m_Key31.EnableWindow(bEnable);
  132. g_pDlg2->m_Key40.EnableWindow(bEnable);
  133. g_pDlg2->m_Key41.EnableWindow(bEnable);
  134. g_pDlg2->m_Key50.EnableWindow(bEnable);
  135. g_pDlg2->m_Key51.EnableWindow(bEnable);
  136. }
  137. LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
  138. {
  139. PKBDLLHOOKSTRUCT pKey;
  140. pKey = (PKBDLLHOOKSTRUCT)lParam;//初始化对象
  141. switch(nCode)
  142. {
  143. case HC_ACTION:
  144. switch (wParam)
  145. {
  146. case WM_SYSKEYDOWN:
  147. switch (pKey->vkCode)
  148. {
  149. case VK_RMENU:
  150. if (theApp.m_bShowHP)
  151. {
  152. keybd_event(0xDB, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
  153. keybd_event(0xDD, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
  154. }
  155. else
  156. {
  157. keybd_event(0xDB, 0, KEYEVENTF_EXTENDEDKEY, 0);
  158. keybd_event(0xDD, 0, KEYEVENTF_EXTENDEDKEY, 0);
  159. }
  160. theApp.m_bShowHP = !theApp.m_bShowHP;
  161. break; 
  162. }
  163. case WM_KEYDOWN:
  164. switch (pKey->vkCode)
  165. {
  166. case VK_DIVIDE:
  167. theApp.m_bChangeKey = !theApp.m_bChangeKey;
  168. EnableEdits(!theApp.m_bChangeKey );
  169. break;
  170. case VK_MULTIPLY:
  171. if (theApp.m_bActive)
  172. {
  173. HWND hWnd=::GetForegroundWindow();
  174. if (bClipCursor)
  175. {
  176. bClipCursor = 0;
  177. CRect r;
  178. CRect c;
  179. ::GetWindowRect(hWnd, &r);
  180. ::GetClientRect(hWnd, &c);
  181. CRect Clip;
  182. Clip.right = r.right - 4;
  183. Clip.bottom = r.bottom - 4;
  184. Clip.top = r.bottom - ( c.bottom - c.top ) - 3;
  185. Clip.left = r.right - ( c.right - c.left ) - 3;
  186. ::ClipCursor(&Clip);
  187. }
  188. else
  189. {
  190. bClipCursor = 1;
  191. ::ClipCursor(NULL);
  192. }
  193. }
  194. break;
  195. }
  196. case WM_KEYUP:
  197. case WM_SYSKEYUP:
  198. if (pKey->vkCode == VK_LWIN)//屏蔽win键
  199. {
  200. return TRUE;
  201. }
  202. break;
  203. }
  204. }
  205. return CallNextHookEx(g_hKeyboard, nCode, wParam, lParam);//传给系统继续处理
  206. }
  207. //初始化钩子
  208. void InitHOOK()
  209. {
  210. g_hKeyboard = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, (HINSTANCE)0x00400000, 0);//安装钩子
  211. }
  212. //卸载钩子
  213. void StopHOOK()
  214. {
  215.     UnhookWindowsHookEx(g_hKeyboard);//卸载钩子
  216. }