WeChatsDlg.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // WeChatsDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "WeChats.h"
  5. #include "WeChatsDlg.h"
  6. #include "CWxObject.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  11. class CAboutDlg : public CDialog
  12. {
  13. public:
  14. CAboutDlg();
  15. // 对话框数据
  16. enum { IDD = IDD_ABOUTBOX };
  17. protected:
  18. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  19. // 实现
  20. protected:
  21. DECLARE_MESSAGE_MAP()
  22. };
  23. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  24. {
  25. }
  26. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. }
  30. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  31. END_MESSAGE_MAP()
  32. // CWeChatsDlg 对话框
  33. HWND g_hWxWnd = NULL;
  34. CWeChatsDlg::CWeChatsDlg(CWnd* pParent /*=NULL*/)
  35. : CDialog(CWeChatsDlg::IDD, pParent)
  36. {
  37. m_bMouseDown = FALSE;
  38. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  39. }
  40. void CWeChatsDlg::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CDialog::DoDataExchange(pDX);
  43. }
  44. BEGIN_MESSAGE_MAP(CWeChatsDlg, CDialog)
  45. ON_WM_SYSCOMMAND()
  46. ON_WM_PAINT()
  47. ON_WM_QUERYDRAGICON()
  48. //}}AFX_MSG_MAP
  49. ON_BN_CLICKED(BTN_OPEN_WX, &CWeChatsDlg::OnBnClickedOpenWx)
  50. ON_WM_CTLCOLOR()
  51. END_MESSAGE_MAP()
  52. // CWeChatsDlg 消息处理程序
  53. BOOL CWeChatsDlg::OnInitDialog()
  54. {
  55. CDialog::OnInitDialog();
  56. // 将“关于...”菜单项添加到系统菜单中。
  57. // IDM_ABOUTBOX 必须在系统命令范围内。
  58. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  59. ASSERT(IDM_ABOUTBOX < 0xF000);
  60. CMenu* pSysMenu = GetSystemMenu(FALSE);
  61. if (pSysMenu != NULL)
  62. {
  63. BOOL bNameValid;
  64. CString strAboutMenu;
  65. bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
  66. ASSERT(bNameValid);
  67. if (!strAboutMenu.IsEmpty())
  68. {
  69. pSysMenu->AppendMenu(MF_SEPARATOR);
  70. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  71. }
  72. }
  73. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  74. // 执行此操作
  75. SetIcon(m_hIcon, TRUE); // 设置大图标
  76. SetIcon(m_hIcon, FALSE); // 设置小图标
  77. // TODO: 在此添加额外的初始化代码
  78. return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
  79. }
  80. void CWeChatsDlg::OnSysCommand(UINT nID, LPARAM lParam)
  81. {
  82. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  83. {
  84. CAboutDlg dlgAbout;
  85. dlgAbout.DoModal();
  86. }
  87. else
  88. {
  89. CDialog::OnSysCommand(nID, lParam);
  90. }
  91. }
  92. // 如果向对话框添加最小化按钮,则需要下面的代码
  93. // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  94. // 这将由框架自动完成。
  95. void CWeChatsDlg::OnPaint()
  96. {
  97. if (IsIconic())
  98. {
  99. CPaintDC dc(this); // 用于绘制的设备上下文
  100. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  101. // 使图标在工作区矩形中居中
  102. int cxIcon = GetSystemMetrics(SM_CXICON);
  103. int cyIcon = GetSystemMetrics(SM_CYICON);
  104. CRect rect;
  105. GetClientRect(&rect);
  106. int x = (rect.Width() - cxIcon + 1) / 2;
  107. int y = (rect.Height() - cyIcon + 1) / 2;
  108. // 绘制图标
  109. dc.DrawIcon(x, y, m_hIcon);
  110. }
  111. else
  112. {
  113. if (m_wxObj.m_hWxMainWnd)
  114. {
  115. Invalidate();
  116. GetDlgItem(WX_RECT)->Invalidate();
  117. ::UpdateWindow(m_wxObj.m_hWxMainWnd);
  118. //::PostMessage(m_wxObj.m_hWxMainWnd, WM_MOVE, 0, 0);
  119. //::PostMessage(m_wxObj.m_hWxMainWnd, WM_WINDOWPOSCHANGING, 0, 0);
  120. }
  121. CDialog::OnPaint();
  122. }
  123. }
  124. //当用户拖动最小化窗口时系统调用此函数取得光标
  125. //显示。
  126. HCURSOR CWeChatsDlg::OnQueryDragIcon()
  127. {
  128. return static_cast<HCURSOR>(m_hIcon);
  129. }
  130. void CWeChatsDlg::OnBnClickedOpenWx()
  131. {
  132. // TODO: 在此添加控件通知处理程序代码
  133. //vector<DWORD> vtPID = FindAllProcess(_T("lyfzServer.exe"));
  134. vector<DWORD> vtPID = FindAllProcess(WECHAT);
  135. //vector<DWORD> vtPID = FindAllProcess(_T("cheatengine-x86_64.exe"));
  136. //vector<DWORD> vtPID = FindAllProcess(_T("AliIM.exe"));
  137. //vector<DWORD> vtPID = FindAllProcess(_T("AliIM.exe"));
  138. if (vtPID.size() != 0)
  139. {
  140. m_wxObj.setInjectionObj(*vtPID.begin(), g_szDynamicLibraryPath);
  141. if (m_wxObj.FindWxMainWnd())
  142. {
  143. m_wxObj.InjectDynamicLibrary();
  144. m_wxObj.Attach2MainWnd(GetDlgItem(WX_RECT), FALSE);
  145. }
  146. }
  147. }
  148. HBRUSH CWeChatsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  149. {
  150. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  151. // TODO: 在此更改 DC 的任何特性
  152. pDC->SetBkMode(TRANSPARENT);
  153. // TODO: 如果默认的不是所需画笔,则返回另一个画笔
  154. return hbr;
  155. }
  156. BOOL CWeChatsDlg::DestroyWindow()
  157. {
  158. // TODO: 在此添加专用代码和/或调用基类
  159. m_wxObj.DetachWxWnd();
  160. return CDialog::DestroyWindow();
  161. }
  162. BOOL CWeChatsDlg::PreTranslateMessage(MSG* pMsg)
  163. {
  164. // TODO: 在此添加专用代码和/或调用基类
  165. if (pMsg->hwnd == m_hWnd)
  166. {
  167. if (pMsg->message == WM_NCLBUTTONDOWN)
  168. {// 非客户区左键按下;
  169. m_bMouseDown = TRUE;
  170. }
  171. if (pMsg->message == WM_NCLBUTTONUP)
  172. {// 非客户区左键放开;
  173. m_bMouseDown = FALSE;
  174. }
  175. if (pMsg->message == WM_NCMOUSEMOVE)
  176. {// 非客户区鼠标移动;
  177. if (m_bMouseDown)
  178. {
  179. Invalidate();
  180. ::UpdateWindow(m_wxObj.m_hWxMainWnd);
  181. ::ShowWindow(m_wxObj.m_hWxMainWnd, SW_SHOW);
  182. WriteTextLog(_T("移动时刷新窗口"));
  183. }
  184. }
  185. //WriteTextLog(_T("窗口:%p, 消息:%d, LP:%d, WP:%d, 时间:%d"), pMsg->hwnd, pMsg->message, pMsg->lParam, pMsg->wParam, pMsg->time);
  186. }
  187. return CDialog::PreTranslateMessage(pMsg);
  188. }