大家可以试试
[mw_shl_code=c,true]# include <stdio.h>
# include <stdlib.h>
# include <windows.h>
# include <Tlhelp32.h> //枚举进程库
# include <string.h>
RECT Rect2;
int PrintfPID (void);//枚举进程
void MouseL (int x,int y);//鼠标左击
void MouseR (int x,int y);//鼠标右击
void ReadMemory (HANDLE q); //读取内存
int main (void)
{
HANDLE WindowHandle,ProcessHandle; //窗口句柄
RECT Rect; //定义矩形数据类型
LPCTSTR lpClassName = "扫雷"; //窗口类名
LPCTSTR lpWindowName = "扫雷"; // 窗口标题
int ProcessPID;
while (1)
{
printf ("按任意键开始\n");
system ("pause");
WindowHandle = FindWindowA (lpClassName,lpWindowName); //返回窗口句柄
GetWindowRect ((HWND)WindowHandle,&Rect); //获取窗口矩形
ProcessPID = PrintfPID ();
ProcessHandle = OpenProcess (PROCESS_ALL_ACCESS,0,ProcessPID);
Rect2.left = Rect.left + 25; //边到雷区有25;
Rect2.top = Rect.top + 110; //顶到雷区有110;
ReadMemory (ProcessHandle);
CloseHandle (ProcessHandle);
}
system ("pause");
return 0;
}
int PrintfPID (void) //枚举进程
{
char ProcessName [12] = "winmine.exe";
PROCESSENTRY32 processInfo;
int judgment;
HANDLE hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);//获取进程快照句柄
processInfo.dwSize = sizeof (processInfo); //设置大小
bool bGetProcess = Process32First ( hSnapshot, &processInfo );//进程入口
while (bGetProcess != false)
{
judgment = lstrcmpi (processInfo.szExeFile,ProcessName);//进程名比较
if (judgment == 0)
break;
bGetProcess = Process32Next (hSnapshot,&processInfo); //获取下一个进程信息
}
judgment = lstrcmpi (processInfo.szExeFile,ProcessName);//再比较一次.以确定最后一个进程退出还是,找到进程名退出
if (judgment == 0)
return processInfo.th32ProcessID; //返回进程PID
else
return 0;
}
void MouseL (int x,int y)//鼠标左击
{
//mouse_event( MOUSEEVENTF_MOVE,x,y,0,0);//鼠标移动
SetCursorPos (x,y);
mouse_event( MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP,0,0,0,0);//鼠标左击.按下与弹起
}
void MouseR (int x,int y)//鼠标右击
{
mouse_event( MOUSEEVENTF_MOVE,x,y,0,0); //鼠标移动
mouse_event( MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP,0,0,0,0);
}
void ReadMemory (HANDLE q) //读取内存
{
MouseL (Rect2.left,Rect2.top);
MouseL (Rect2.left,Rect2.top);
int i,l,c,line = 1,x,a;
PVOID h;
int level;
char ch[9];
int Memory = 16798561;
//MouseL (Rect2.left,Rect2.top);
//MouseL (Rect2.left,Rect2.top);
//printf ("%d %d", Rect2.left,Rect2.top);
for (i = 1; i <= 720; ++i,++a)
{
ReadProcessMemory(q,(LPCVOID)Memory,&h,4,0);
level = (int)h;
//printf ("%x %d\n",h,Memory);
sprintf (ch,"%x",level);
Memory = Memory + 1;
if (strlen (ch) < 8)
{
printf ("%c%c ",ch[5],ch[6]);
if ( (ch[5] != '8') && (ch[6] != 'a') )
{
//printf ("%c%c ",ch[5],ch[6]);
MouseL (Rect2.left,Rect2.top);
}
}
else
{
printf ("%c%c ",ch[6],ch[7]);
if ( (ch[6] != '8')&& (ch[7] != 'a') ) //8F等于雷
{
//printf ("%c%c ",ch[6],ch[7]);
//printf ("%c%c ",ch[6],ch[7]);
MouseL (Rect2.left,Rect2.top);
//printf ("%d %d\n",Rect2.left,Rect2.top);
//printf ("%s ",ch);
}
}
Rect2.left = Rect2.left + 16;
if (i == 30 * line)
{
Memory = Memory + 2;
++line;
a = 1;
Rect2.left = Rect2.left - 480;
Rect2.top = Rect2.top + 16;
printf ("\n");
}
//Sleep (50);
}
} [/mw_shl_code]
|