123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- // GameAssistDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "GameAssist.h"
- #include "GameAssistDlg.h"
- #include "VideoDXGICaptor.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // 对话框数据
- enum { IDD = IDD_ABOUTBOX };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
- // 实现
- protected:
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- END_MESSAGE_MAP()
- // CGameAssistDlg 对话框
- CGameAssistDlg::CGameAssistDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CGameAssistDlg::IDD, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CGameAssistDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CGameAssistDlg, CDialog)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- ON_BN_CLICKED(BTN_OPENGAME, &CGameAssistDlg::OnBnClickedOpengame)
- ON_BN_CLICKED(IDC_BUTTON2, &CGameAssistDlg::OnBnClickedButton2)
- END_MESSAGE_MAP()
- // CGameAssistDlg 消息处理程序
- BOOL CGameAssistDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 将“关于...”菜单项添加到系统菜单中。
- // IDM_ABOUTBOX 必须在系统命令范围内。
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- BOOL bNameValid;
- CString strAboutMenu;
- bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
- ASSERT(bNameValid);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
- // 执行此操作
- SetIcon(m_hIcon, TRUE); // 设置大图标
- SetIcon(m_hIcon, FALSE); // 设置小图标
- // TODO: 在此添加额外的初始化代码
- return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
- }
- void CGameAssistDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // 如果向对话框添加最小化按钮,则需要下面的代码
- // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
- // 这将由框架自动完成。
- void CGameAssistDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
- // 使图标在工作区矩形中居中
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // 绘制图标
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- //当用户拖动最小化窗口时系统调用此函数取得光标
- //显示。
- HCURSOR CGameAssistDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void CGameAssistDlg::OnBnClickedOpengame()
- {
- #if 1 // 获取游戏标题;
- DWORD dwPid = GAssist::FindProcess(_T("Game.exe"));
- HWND hProWnd = GAssist::GetProHwnd(dwPid);
- //HWND hProWnd = GAssist::GetProHwnd(5824);
- TCHAR szWinText[MAX_PATH] = {0};
- ::GetWindowText(hProWnd, szWinText, MAX_PATH);
- RECT rc = {0,0,500,500};
- HBITMAP hb = GAssist::CopyDC2Bitmap(hProWnd, &rc);
- GAssist::SaveBitmap(hb, "D:\\1.bmp");
- GAssist::SaveHwndToBmpFile(hProWnd, "D:\\2.bmp");
- return;
- #endif
- // TODO: 在此添加控件通知处理程序代码
- if ( !PathFileExists(GAssist::g_szGamePath) )
- {
- MessageBox("游戏程序不存在", "温馨提示");
- return;
- }
- // 设置辅助程序工作目录为游戏目录;
- //SetCurrentDirectory(_T("E:\\dhsh\\shdata\\"));
- SetCurrentDirectory(_T("D:\\tools\\dhsh\\shdata\\"));
- #if 1
- ShellExecute(NULL, "open", GAssist::g_szGamePath, NULL, NULL, SW_SHOWNORMAL);//SW_HIDE无用,因为会自动结;
- Sleep(500); // Main.exe设置了陷阱(自己再开启了一个进程,结束上一个进程),需要等5秒;
- #else
- SHELLEXECUTEINFO stuExecInfo = { 0 };
- DWORD dwExitCode = STILL_ACTIVE;
- //CString strCommandLine = _T("open");
- stuExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
- stuExecInfo.lpFile = GAssist::g_szGamePath;
- stuExecInfo.lpParameters = "open";
- stuExecInfo.nShow = SW_SHOWNORMAL;
- stuExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
- if (!ShellExecuteEx(&stuExecInfo))
- {
- DWORD dwError = GetLastError();
- CString strError = _T("");
- strError.Format(_T("执行ShellExecuteEx失败,错误码:%d"),dwError);
- AfxMessageBox(strError);
- return ;
- }
- HANDLE hProcess = stuExecInfo.hProcess;
- if ( hProcess != NULL )
- {
- WaitForSingleObject(hProcess,INFINITE);
- CloseHandle(hProcess);
- }
- #endif
- DWORD dwPID = GAssist::FindProcess(_T("Main.exe"));
- #if 1
- EnumWindows(GAssist::EnumChildWindowCallBack, dwPID);
- if ( GAssist::g_vtGameHwnd.size() )
- {
- GAssist::GameHwnd* gp = NULL;
- GAssist::GameHwnd* gbmin = NULL;
- GAssist::GameHwnd* gbentry = NULL;
- for ( std::vector<GAssist::GameHwnd>::iterator it = GAssist::g_vtGameHwnd.begin(); it != GAssist::g_vtGameHwnd.end(); it++ )
- {
- if ( _tcsicmp(it->strWinText.c_str(), _T("最小化")) == 0 )
- {
- gbmin = &*it;
- }
- if ( _tcsicmp(it->strWinText.c_str(), _T("大话水浒")) == 0 )
- {
- gp = &*it;
- }
- if ( _tcsicmp(it->strWinText.c_str(), _T("进入游戏")) == 0 )
- {
- gbentry = &*it;
- }
- }
- if ( gp && gbentry && gbmin)
- {
- //::SendMessage(gp->hwnd, WM_LBUTTONDOWN, (WPARAM)gb->dwId, 0);
- //::SendMessage(gp->hwnd, WM_LBUTTONUP, (WPARAM)gb->dwId, 0);
- // 发送点击事件;
- // 先最小化;
- ::SendMessage(gp->hwnd,WM_COMMAND,gbmin->dwId,NULL);
- // 再进入;
- ::SendMessage(gp->hwnd,WM_COMMAND,gbentry->dwId,NULL);
- Sleep(1500);
- dwPID = GAssist::FindProcess(_T("Game.exe"));
- if ( dwPID )
- {
- GAssist::g_vtGameHwnd.clear();
- EnumWindows(GAssist::EnumChildWindowCallBack, dwPID);
- HWND hwnd = GAssist::GetProHwnd(dwPID);
- if ( hwnd )
- {
- TCHAR szName[MAX_PATH] = {0};
- ::GetWindowText(hwnd, szName, MAX_PATH);
- CRect rc;
- ::GetWindowRect(hwnd, &rc);
- TCHAR szLogMsg[MAX_PATH] = {0};
- _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());
- OutputDebugString(szLogMsg);
- if ( 1 )
- { // 800x600
- // 发送按钮消息;进入游戏;
- GAssist::MouseClick(hwnd, 585, 116);
- // 发送按钮消息;下一步;
- GAssist::MouseClick(hwnd, 536, 481);
- // 发送按钮消息;电信一区;
- GAssist::MouseClick(hwnd, 229, 342);
- // 发送按钮消息;忘忧谷;
- GAssist::MouseClick(hwnd, 335, 244);
- // 发送按钮消息;下一步;
- GAssist::MouseClick(hwnd, 559, 516);
- }
- else
- {
- // 640x480
- // 发送按钮消息;进入游戏;
- GAssist::MouseClick(hwnd, 440, 75);
- // 发送按钮消息;下一步;
- GAssist::MouseClick(hwnd, 468, 454);
- // 发送按钮消息;电信一区;
- GAssist::MouseClick(hwnd, 165, 241);
- // 发送按钮消息;忘忧谷;
- GAssist::MouseClick(hwnd, 289, 195);
- // 发送按钮消息;下一步;
- GAssist::MouseClick(hwnd, 494, 469);
- }
- }
- }
- }
- }
- #endif
- }
- void CGameAssistDlg::OnBnClickedButton2()
- {
- // TODO: 在此添加控件通知处理程序代码
-
- VideoDXGICaptor vdx;
- if (vdx.Init())
- {
- INT len = 1024 * 1024 * 1024;
- BYTE* pData = new BYTE[len];
- vdx.CaptureImage(pData, len);
- vdx.Deinit();
- }
- }
|