WeChatsDlg.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 (m_wxObj.m_hWxMainWnd)
  113. {
  114. Invalidate();
  115. GetDlgItem(WX_RECT)->Invalidate();
  116. ::UpdateWindow(m_wxObj.m_hWxMainWnd);
  117. //::PostMessage(m_wxObj.m_hWxMainWnd, WM_MOVE, 0, 0);
  118. //::PostMessage(m_wxObj.m_hWxMainWnd, WM_WINDOWPOSCHANGING, 0, 0);
  119. }
  120. CDialog::OnPaint();
  121. }
  122. }
  123. //当用户拖动最小化窗口时系统调用此函数取得光标
  124. //显示。
  125. HCURSOR CWeChatsDlg::OnQueryDragIcon()
  126. {
  127. return static_cast<HCURSOR>(m_hIcon);
  128. }
  129. void CWeChatsDlg::OnBnClickedOpenWx()
  130. {
  131. // TODO: 在此添加控件通知处理程序代码
  132. #ifdef _DEBUG
  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. #endif
  148. }
  149. HBRUSH CWeChatsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  150. {
  151. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  152. // TODO: 在此更改 DC 的任何特性
  153. //pDC->SetBkMode(TRANSPARENT);
  154. // TODO: 如果默认的不是所需画笔,则返回另一个画笔
  155. return hbr;
  156. }
  157. BOOL CWeChatsDlg::DestroyWindow()
  158. {
  159. // TODO: 在此添加专用代码和/或调用基类
  160. m_wxObj.DetachWxWnd();
  161. //m_wxObj.EjectDynamicLibrary();
  162. return CDialog::DestroyWindow();
  163. }