#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<<"no" ; return false; } cout<<"进程"<<pid; hProcess=OpenProcess(PROCESS_ALL_ACCESS,false,pid); if(hProcess==NULL){ cout<<"no open process"; return false; } cout<<"打开进程:"<<hProcess<<endl; DWORD BaseAddress=0x006A9EC0; bool Result=ReadProcessMemory(hProcess,(LPVOID)BaseAddress,&BaseValue,4,NULL); if(Result==false) { cout<<"lose"; return false; } }
标签:Plants,startGame,游戏,hand,vs,bool,Result,Zombies,NULL From: https://www.cnblogs.com/hanxuyao/p/17904119.html