GameAssistDlg.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. // GameAssistDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "GameAssist.h"
  5. #include "GameAssistDlg.h"
  6. //#include "VideoDXGICaptor.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. // CGameAssistDlg 对话框
  33. CGameAssistDlg::CGameAssistDlg(CWnd* pParent /*=NULL*/)
  34. : CDialog(CGameAssistDlg::IDD, pParent)
  35. {
  36. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  37. }
  38. void CGameAssistDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. }
  42. BEGIN_MESSAGE_MAP(CGameAssistDlg, CDialog)
  43. ON_WM_SYSCOMMAND()
  44. ON_WM_PAINT()
  45. ON_WM_QUERYDRAGICON()
  46. //}}AFX_MSG_MAP
  47. ON_BN_CLICKED(BTN_OPENGAME, &CGameAssistDlg::OnBnClickedOpengame)
  48. ON_BN_CLICKED(IDC_BUTTON2, &CGameAssistDlg::OnBnClickedButton2)
  49. END_MESSAGE_MAP()
  50. // CGameAssistDlg 消息处理程序
  51. BOOL CGameAssistDlg::OnInitDialog()
  52. {
  53. CDialog::OnInitDialog();
  54. // 将“关于...”菜单项添加到系统菜单中。
  55. // IDM_ABOUTBOX 必须在系统命令范围内。
  56. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  57. ASSERT(IDM_ABOUTBOX < 0xF000);
  58. CMenu* pSysMenu = GetSystemMenu(FALSE);
  59. if (pSysMenu != NULL)
  60. {
  61. BOOL bNameValid;
  62. CString strAboutMenu;
  63. bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
  64. ASSERT(bNameValid);
  65. if (!strAboutMenu.IsEmpty())
  66. {
  67. pSysMenu->AppendMenu(MF_SEPARATOR);
  68. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  69. }
  70. }
  71. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  72. // 执行此操作
  73. SetIcon(m_hIcon, TRUE); // 设置大图标
  74. SetIcon(m_hIcon, FALSE); // 设置小图标
  75. // TODO: 在此添加额外的初始化代码
  76. return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
  77. }
  78. void CGameAssistDlg::OnSysCommand(UINT nID, LPARAM lParam)
  79. {
  80. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  81. {
  82. CAboutDlg dlgAbout;
  83. dlgAbout.DoModal();
  84. }
  85. else
  86. {
  87. CDialog::OnSysCommand(nID, lParam);
  88. }
  89. }
  90. // 如果向对话框添加最小化按钮,则需要下面的代码
  91. // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  92. // 这将由框架自动完成。
  93. void CGameAssistDlg::OnPaint()
  94. {
  95. if (IsIconic())
  96. {
  97. CPaintDC dc(this); // 用于绘制的设备上下文
  98. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  99. // 使图标在工作区矩形中居中
  100. int cxIcon = GetSystemMetrics(SM_CXICON);
  101. int cyIcon = GetSystemMetrics(SM_CYICON);
  102. CRect rect;
  103. GetClientRect(&rect);
  104. int x = (rect.Width() - cxIcon + 1) / 2;
  105. int y = (rect.Height() - cyIcon + 1) / 2;
  106. // 绘制图标
  107. dc.DrawIcon(x, y, m_hIcon);
  108. }
  109. else
  110. {
  111. CDialog::OnPaint();
  112. }
  113. }
  114. //当用户拖动最小化窗口时系统调用此函数取得光标
  115. //显示。
  116. HCURSOR CGameAssistDlg::OnQueryDragIcon()
  117. {
  118. return static_cast<HCURSOR>(m_hIcon);
  119. }
  120. void CGameAssistDlg::OnBnClickedOpengame()
  121. {
  122. #if 1 // 获取游戏标题;
  123. DWORD dwPid = GAssist::FindProcess(_T("Game.exe"));
  124. HWND hProWnd = GAssist::GetProHwnd(dwPid);
  125. //HWND hProWnd = GAssist::GetProHwnd(5824);
  126. TCHAR szWinText[MAX_PATH] = {0};
  127. ::GetWindowText(hProWnd, szWinText, MAX_PATH);
  128. Sleep(5000);
  129. GAssist::MouseMove(hProWnd, CPoint(100,100), CPoint(200,200));
  130. Sleep(2000);
  131. GAssist::MouseMove(hProWnd, CPoint(100,100), CPoint(250,250));
  132. Sleep(2000);
  133. GAssist::MouseMove(hProWnd, CPoint(100,100), CPoint(350,350));
  134. RECT rc = {0,0,500,500};
  135. HBITMAP hb = GAssist::CopyDC2Bitmap(hProWnd, &rc);
  136. GAssist::SaveBitmap(hb, "D:\\1.bmp");
  137. GAssist::SaveHwndToBmpFile(hProWnd, "D:\\2.bmp");
  138. return;
  139. #endif
  140. // TODO: 在此添加控件通知处理程序代码
  141. if ( !PathFileExists(GAssist::g_szGamePath) )
  142. {
  143. MessageBox("游戏程序不存在", "温馨提示");
  144. return;
  145. }
  146. // 设置辅助程序工作目录为游戏目录;
  147. //SetCurrentDirectory(_T("E:\\dhsh\\shdata\\"));
  148. SetCurrentDirectory(_T("D:\\tools\\dhsh\\shdata\\"));
  149. #if 1
  150. ShellExecute(NULL, "open", GAssist::g_szGamePath, NULL, NULL, SW_SHOWNORMAL);//SW_HIDE无用,因为会自动结;
  151. Sleep(500); // Main.exe设置了陷阱(自己再开启了一个进程,结束上一个进程),需要等5秒;
  152. #else
  153. SHELLEXECUTEINFO stuExecInfo = { 0 };
  154. DWORD dwExitCode = STILL_ACTIVE;
  155. //CString strCommandLine = _T("open");
  156. stuExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  157. stuExecInfo.lpFile = GAssist::g_szGamePath;
  158. stuExecInfo.lpParameters = "open";
  159. stuExecInfo.nShow = SW_SHOWNORMAL;
  160. stuExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
  161. if (!ShellExecuteEx(&stuExecInfo))
  162. {
  163. DWORD dwError = GetLastError();
  164. CString strError = _T("");
  165. strError.Format(_T("执行ShellExecuteEx失败,错误码:%d"),dwError);
  166. AfxMessageBox(strError);
  167. return ;
  168. }
  169. HANDLE hProcess = stuExecInfo.hProcess;
  170. if ( hProcess != NULL )
  171. {
  172. WaitForSingleObject(hProcess,INFINITE);
  173. CloseHandle(hProcess);
  174. }
  175. #endif
  176. DWORD dwPID = GAssist::FindProcess(_T("Main.exe"));
  177. #if 1
  178. EnumWindows(GAssist::EnumChildWindowCallBack, dwPID);
  179. if ( GAssist::g_vtGameHwnd.size() )
  180. {
  181. GAssist::GameHwnd* gp = NULL;
  182. GAssist::GameHwnd* gbmin = NULL;
  183. GAssist::GameHwnd* gbentry = NULL;
  184. for ( std::vector<GAssist::GameHwnd>::iterator it = GAssist::g_vtGameHwnd.begin(); it != GAssist::g_vtGameHwnd.end(); it++ )
  185. {
  186. if ( _tcsicmp(it->strWinText.c_str(), _T("最小化")) == 0 )
  187. {
  188. gbmin = &*it;
  189. }
  190. if ( _tcsicmp(it->strWinText.c_str(), _T("大话水浒")) == 0 )
  191. {
  192. gp = &*it;
  193. }
  194. if ( _tcsicmp(it->strWinText.c_str(), _T("进入游戏")) == 0 )
  195. {
  196. gbentry = &*it;
  197. }
  198. }
  199. if ( gp && gbentry && gbmin)
  200. {
  201. //::SendMessage(gp->hwnd, WM_LBUTTONDOWN, (WPARAM)gb->dwId, 0);
  202. //::SendMessage(gp->hwnd, WM_LBUTTONUP, (WPARAM)gb->dwId, 0);
  203. // 发送点击事件;
  204. // 先最小化;
  205. ::SendMessage(gp->hwnd,WM_COMMAND,gbmin->dwId,NULL);
  206. // 再进入;
  207. ::SendMessage(gp->hwnd,WM_COMMAND,gbentry->dwId,NULL);
  208. Sleep(1500);
  209. dwPID = GAssist::FindProcess(_T("Game.exe"));
  210. if ( dwPID )
  211. {
  212. GAssist::g_vtGameHwnd.clear();
  213. EnumWindows(GAssist::EnumChildWindowCallBack, dwPID);
  214. HWND hwnd = GAssist::GetProHwnd(dwPID);
  215. if ( hwnd )
  216. {
  217. TCHAR szName[MAX_PATH] = {0};
  218. ::GetWindowText(hwnd, szName, MAX_PATH);
  219. CRect rc;
  220. ::GetWindowRect(hwnd, &rc);
  221. TCHAR szLogMsg[MAX_PATH] = {0};
  222. _stprintf_s(szLogMsg, _T("窗口标题:%s, [%d,%d, %d,%d], width=%d, height=%d\n"), szName, rc.top, rc.left, rc.right, rc.bottom, rc.Width(), rc.Height());
  223. OutputDebugString(szLogMsg);
  224. if ( 1 )
  225. { // 800x600
  226. // 发送按钮消息;进入游戏;
  227. GAssist::MouseClick(hwnd, 585, 116);
  228. // 发送按钮消息;下一步;
  229. GAssist::MouseClick(hwnd, 536, 481);
  230. // 发送按钮消息;电信一区;
  231. GAssist::MouseClick(hwnd, 229, 342);
  232. // 发送按钮消息;忘忧谷;
  233. GAssist::MouseClick(hwnd, 335, 244);
  234. // 发送按钮消息;下一步;
  235. GAssist::MouseClick(hwnd, 559, 516);
  236. }
  237. else
  238. {
  239. // 640x480
  240. // 发送按钮消息;进入游戏;
  241. GAssist::MouseClick(hwnd, 440, 75);
  242. // 发送按钮消息;下一步;
  243. GAssist::MouseClick(hwnd, 468, 454);
  244. // 发送按钮消息;电信一区;
  245. GAssist::MouseClick(hwnd, 165, 241);
  246. // 发送按钮消息;忘忧谷;
  247. GAssist::MouseClick(hwnd, 289, 195);
  248. // 发送按钮消息;下一步;
  249. GAssist::MouseClick(hwnd, 494, 469);
  250. }
  251. }
  252. }
  253. }
  254. }
  255. #endif
  256. }
  257. void CGameAssistDlg::OnBnClickedButton2()
  258. {
  259. // TODO: 在此添加控件通知处理程序代码
  260. // VideoDXGICaptor vdx;
  261. // if (vdx.Init())
  262. // {
  263. // INT len = 1024 * 1024 * 1024;
  264. // BYTE* pData = new BYTE[len];
  265. // vdx.CaptureImage(pData, len);
  266. // vdx.Deinit();
  267. // }
  268. }