GameAssistDlg.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. RECT rc = {0,0,500,500};
  129. HBITMAP hb = GAssist::CopyDC2Bitmap(hProWnd, &rc);
  130. GAssist::SaveBitmap(hb, "D:\\1.bmp");
  131. GAssist::SaveHwndToBmpFile(hProWnd, "D:\\2.bmp");
  132. return;
  133. #endif
  134. // TODO: 在此添加控件通知处理程序代码
  135. if ( !PathFileExists(GAssist::g_szGamePath) )
  136. {
  137. MessageBox("游戏程序不存在", "温馨提示");
  138. return;
  139. }
  140. // 设置辅助程序工作目录为游戏目录;
  141. //SetCurrentDirectory(_T("E:\\dhsh\\shdata\\"));
  142. SetCurrentDirectory(_T("D:\\tools\\dhsh\\shdata\\"));
  143. #if 1
  144. ShellExecute(NULL, "open", GAssist::g_szGamePath, NULL, NULL, SW_SHOWNORMAL);//SW_HIDE无用,因为会自动结;
  145. Sleep(500); // Main.exe设置了陷阱(自己再开启了一个进程,结束上一个进程),需要等5秒;
  146. #else
  147. SHELLEXECUTEINFO stuExecInfo = { 0 };
  148. DWORD dwExitCode = STILL_ACTIVE;
  149. //CString strCommandLine = _T("open");
  150. stuExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  151. stuExecInfo.lpFile = GAssist::g_szGamePath;
  152. stuExecInfo.lpParameters = "open";
  153. stuExecInfo.nShow = SW_SHOWNORMAL;
  154. stuExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
  155. if (!ShellExecuteEx(&stuExecInfo))
  156. {
  157. DWORD dwError = GetLastError();
  158. CString strError = _T("");
  159. strError.Format(_T("执行ShellExecuteEx失败,错误码:%d"),dwError);
  160. AfxMessageBox(strError);
  161. return ;
  162. }
  163. HANDLE hProcess = stuExecInfo.hProcess;
  164. if ( hProcess != NULL )
  165. {
  166. WaitForSingleObject(hProcess,INFINITE);
  167. CloseHandle(hProcess);
  168. }
  169. #endif
  170. DWORD dwPID = GAssist::FindProcess(_T("Main.exe"));
  171. #if 1
  172. EnumWindows(GAssist::EnumChildWindowCallBack, dwPID);
  173. if ( GAssist::g_vtGameHwnd.size() )
  174. {
  175. GAssist::GameHwnd* gp = NULL;
  176. GAssist::GameHwnd* gbmin = NULL;
  177. GAssist::GameHwnd* gbentry = NULL;
  178. for ( std::vector<GAssist::GameHwnd>::iterator it = GAssist::g_vtGameHwnd.begin(); it != GAssist::g_vtGameHwnd.end(); it++ )
  179. {
  180. if ( _tcsicmp(it->strWinText.c_str(), _T("最小化")) == 0 )
  181. {
  182. gbmin = &*it;
  183. }
  184. if ( _tcsicmp(it->strWinText.c_str(), _T("大话水浒")) == 0 )
  185. {
  186. gp = &*it;
  187. }
  188. if ( _tcsicmp(it->strWinText.c_str(), _T("进入游戏")) == 0 )
  189. {
  190. gbentry = &*it;
  191. }
  192. }
  193. if ( gp && gbentry && gbmin)
  194. {
  195. //::SendMessage(gp->hwnd, WM_LBUTTONDOWN, (WPARAM)gb->dwId, 0);
  196. //::SendMessage(gp->hwnd, WM_LBUTTONUP, (WPARAM)gb->dwId, 0);
  197. // 发送点击事件;
  198. // 先最小化;
  199. ::SendMessage(gp->hwnd,WM_COMMAND,gbmin->dwId,NULL);
  200. // 再进入;
  201. ::SendMessage(gp->hwnd,WM_COMMAND,gbentry->dwId,NULL);
  202. Sleep(1500);
  203. dwPID = GAssist::FindProcess(_T("Game.exe"));
  204. if ( dwPID )
  205. {
  206. GAssist::g_vtGameHwnd.clear();
  207. EnumWindows(GAssist::EnumChildWindowCallBack, dwPID);
  208. HWND hwnd = GAssist::GetProHwnd(dwPID);
  209. if ( hwnd )
  210. {
  211. TCHAR szName[MAX_PATH] = {0};
  212. ::GetWindowText(hwnd, szName, MAX_PATH);
  213. CRect rc;
  214. ::GetWindowRect(hwnd, &rc);
  215. TCHAR szLogMsg[MAX_PATH] = {0};
  216. _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());
  217. OutputDebugString(szLogMsg);
  218. if ( 1 )
  219. { // 800x600
  220. // 发送按钮消息;进入游戏;
  221. GAssist::MouseClick(hwnd, 585, 116);
  222. // 发送按钮消息;下一步;
  223. GAssist::MouseClick(hwnd, 536, 481);
  224. // 发送按钮消息;电信一区;
  225. GAssist::MouseClick(hwnd, 229, 342);
  226. // 发送按钮消息;忘忧谷;
  227. GAssist::MouseClick(hwnd, 335, 244);
  228. // 发送按钮消息;下一步;
  229. GAssist::MouseClick(hwnd, 559, 516);
  230. }
  231. else
  232. {
  233. // 640x480
  234. // 发送按钮消息;进入游戏;
  235. GAssist::MouseClick(hwnd, 440, 75);
  236. // 发送按钮消息;下一步;
  237. GAssist::MouseClick(hwnd, 468, 454);
  238. // 发送按钮消息;电信一区;
  239. GAssist::MouseClick(hwnd, 165, 241);
  240. // 发送按钮消息;忘忧谷;
  241. GAssist::MouseClick(hwnd, 289, 195);
  242. // 发送按钮消息;下一步;
  243. GAssist::MouseClick(hwnd, 494, 469);
  244. }
  245. }
  246. }
  247. }
  248. }
  249. #endif
  250. }
  251. void CGameAssistDlg::OnBnClickedButton2()
  252. {
  253. // TODO: 在此添加控件通知处理程序代码
  254. VideoDXGICaptor vdx;
  255. if (vdx.Init())
  256. {
  257. INT len = 1024 * 1024 * 1024;
  258. BYTE* pData = new BYTE[len];
  259. vdx.CaptureImage(pData, len);
  260. vdx.Deinit();
  261. }
  262. }