WeChatsDlg.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  38. }
  39. void CWeChatsDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CDialog::DoDataExchange(pDX);
  42. }
  43. BEGIN_MESSAGE_MAP(CWeChatsDlg, CDialog)
  44. ON_WM_SYSCOMMAND()
  45. ON_WM_PAINT()
  46. ON_WM_QUERYDRAGICON()
  47. //}}AFX_MSG_MAP
  48. ON_BN_CLICKED(BTN_OPEN_WX, &CWeChatsDlg::OnBnClickedOpenWx)
  49. ON_WM_CTLCOLOR()
  50. END_MESSAGE_MAP()
  51. // CWeChatsDlg 消息处理程序
  52. BOOL CWeChatsDlg::OnInitDialog()
  53. {
  54. CDialog::OnInitDialog();
  55. // 将“关于...”菜单项添加到系统菜单中。
  56. // IDM_ABOUTBOX 必须在系统命令范围内。
  57. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  58. ASSERT(IDM_ABOUTBOX < 0xF000);
  59. CMenu* pSysMenu = GetSystemMenu(FALSE);
  60. if (pSysMenu != NULL)
  61. {
  62. BOOL bNameValid;
  63. CString strAboutMenu;
  64. bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
  65. ASSERT(bNameValid);
  66. if (!strAboutMenu.IsEmpty())
  67. {
  68. pSysMenu->AppendMenu(MF_SEPARATOR);
  69. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  70. }
  71. }
  72. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  73. // 执行此操作
  74. SetIcon(m_hIcon, TRUE); // 设置大图标
  75. SetIcon(m_hIcon, FALSE); // 设置小图标
  76. // TODO: 在此添加额外的初始化代码
  77. return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
  78. }
  79. void CWeChatsDlg::OnSysCommand(UINT nID, LPARAM lParam)
  80. {
  81. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  82. {
  83. CAboutDlg dlgAbout;
  84. dlgAbout.DoModal();
  85. }
  86. else
  87. {
  88. CDialog::OnSysCommand(nID, lParam);
  89. }
  90. }
  91. // 如果向对话框添加最小化按钮,则需要下面的代码
  92. // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  93. // 这将由框架自动完成。
  94. void CWeChatsDlg::OnPaint()
  95. {
  96. if (IsIconic())
  97. {
  98. CPaintDC dc(this); // 用于绘制的设备上下文
  99. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  100. // 使图标在工作区矩形中居中
  101. int cxIcon = GetSystemMetrics(SM_CXICON);
  102. int cyIcon = GetSystemMetrics(SM_CYICON);
  103. CRect rect;
  104. GetClientRect(&rect);
  105. int x = (rect.Width() - cxIcon + 1) / 2;
  106. int y = (rect.Height() - cyIcon + 1) / 2;
  107. // 绘制图标
  108. dc.DrawIcon(x, y, m_hIcon);
  109. }
  110. else
  111. {
  112. if (g_hWxWnd)
  113. ::UpdateWindow(g_hWxWnd);
  114. CDialog::OnPaint();
  115. }
  116. }
  117. //当用户拖动最小化窗口时系统调用此函数取得光标
  118. //显示。
  119. HCURSOR CWeChatsDlg::OnQueryDragIcon()
  120. {
  121. return static_cast<HCURSOR>(m_hIcon);
  122. }
  123. void CWeChatsDlg::OnBnClickedOpenWx()
  124. {
  125. // TODO: 在此添加控件通知处理程序代码
  126. #ifdef _DEBUG
  127. //vector<DWORD> vtPID = FindAllProcess(_T("lyfzServer.exe"));
  128. vector<DWORD> vtPID = FindAllProcess(WECHAT);
  129. //vector<DWORD> vtPID = FindAllProcess(_T("cheatengine-x86_64.exe"));
  130. //vector<DWORD> vtPID = FindAllProcess(_T("AliIM.exe"));
  131. //vector<DWORD> vtPID = FindAllProcess(_T("AliIM.exe"));
  132. if (vtPID.size() != 0)
  133. {
  134. CWxObject wxobj(*vtPID.begin(), _T("E:\\bin\\WeChats2017\\hook.dll"));
  135. //if (wxobj.FindWxMainWnd())
  136. if (wxobj.FindWxLoginWnd())
  137. {
  138. //g_hWxWnd = wxobj.GetWxMainWnd();
  139. g_hWxWnd = wxobj.GetWxLoginWnd();
  140. if (g_hWxWnd != NULL)
  141. {
  142. // 获取微信窗口的样式;
  143. DWORD dwStyle = ::GetWindowLong(g_hWxWnd, GWL_STYLE);
  144. // WS_CLIPSIBLINGS告诉父窗口不要绘制子窗口出现的区域;
  145. dwStyle |= WS_CLIPSIBLINGS;
  146. // 重新设置窗口样式 ;
  147. ::SetWindowLong(g_hWxWnd, GWL_STYLE, dwStyle);
  148. CRect rect;
  149. GetDlgItem(WX_RECT)->GetWindowRect(&rect);
  150. // 设置背景透明;
  151. ::SetParent(g_hWxWnd, GetDlgItem(WX_RECT)->m_hWnd);//set parent of ms paint to our dialog.
  152. //::SetParent(hWxWnd, m_hWnd);
  153. // 擦除背景;
  154. //SetWindowLong(hWxWnd, GWL_STYLE, WS_VISIBLE);//eraze title of ms paint window.
  155. //Positioning ms paint.
  156. ScreenToClient(wxobj.m_rcWnd);
  157. ::MoveWindow(g_hWxWnd, wxobj.m_rcWnd.left, wxobj.m_rcWnd.top, wxobj.m_rcWnd.right, wxobj.m_rcWnd.bottom, true);
  158. //ClientToScreen(&rect);
  159. //ScreenToClient(&rect);
  160. //::SetWindowPos(hWxWnd, NULL, rect.left, rect.top, rect.right, rect.bottom, SWP_SHOWWINDOW | SWP_HIDEWINDOW);
  161. //窗口重绘,(因创建exe时,设置为SW_HIDE,导致exe窗口会被父窗口覆盖一部分)
  162. //Invalidate();
  163. ::UpdateWindow(g_hWxWnd);
  164. ::ShowWindow(g_hWxWnd, SW_SHOW);
  165. }
  166. }
  167. }
  168. #endif
  169. }
  170. HBRUSH CWeChatsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  171. {
  172. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  173. // TODO: 在此更改 DC 的任何特性
  174. //pDC->SetBkMode(TRANSPARENT);
  175. // TODO: 如果默认的不是所需画笔,则返回另一个画笔
  176. return hbr;
  177. }