#include <iostream> #include <windows.h> using namespace std; //声明变量 HWND hand = NULL;//游戏窗口 DWORD pid = 0;//游戏进程ID HANDLE hProcess = NULL;//进程对象 DWORD BaseValue = 0;//游戏数据存放的基础值 bool startGame();//初始化游戏数据 int main(){ bool Result = false; Result = startGame(); if(Result==false){ return 0; } return 0; } bool startGame(){ //查找电脑是否运行了植物大战僵尸 hand = FindWindow("MainWindow","植物大战僵尸中文版"); if(hand==NULL){ cout<<"游戏没有运行"; return false; } cout<<"窗口:"<<hand<<endl; GetWindowThreadProcessId(hand,&pid); if(pid==0){ cout<<"无法找到植物大战僵尸进程"; return false; } cout<<"进程:"<<pid<<endl; hProcess = OpenProcess(PROCESS_ALL_ACCESS,false,pid); if(hProcess==NULL){ cout<<"无法打开进程"<<endl; return false; } cout<<"打开进程:"<<hProcess<<endl; DWORD BaseAddress = 0x006A9EC0;//获取游戏的基础地址 bool Result = ReadProcessMemory(hProcess,(LPVOID)BaseAddress,&BaseValue,4,NULL); if(Result==false){ cout<<"初始化基础地址失败"<<endl; return false; } return true; }
标签:startGame,僵尸,植物,大战,hand,bool,Result,NULL From: https://www.cnblogs.com/wangyihang-xh/p/17904096.html