一个查找扫雷游戏雷位置的程序。
程序原理:读取扫雷进程内存,在内存中读出雷格大小,雷的个数,按雷的标致算出雷所在位置,并在有雷处注明雷字。
使用帮助:下载并运行探雷者,点起动扫雷按扭就会运行扫雷游戏,再点查找地雷。点停止计时按扭可以停止游戏中的计时。有兴趣的朋友可以看看程序原代码。
注:程序只在VC++ 6.0 XP 下测试通过。2000下好象也可以。
程序下载:http://www.cnitblog.com/Files/walaog/mine.rar
程序源码如下:
#include "stdAfx.h"
#include "resource.h"
#include <shellapi.h>
#define My_Tray_Message WM_USER+10
// /////////////////////////////////////////////////////////
// 程序用途:查找扫雷游戏雷区位置的程序。
// 适用系统: windows XP,windows 2000
// 作者: gym
// mail: net_gym@163.com
// 日期: 2006/06/27 写于新疆
// 注:若欲转载,请保持代码与此段完整性.
并注明出处:http://www.cnitblog.com/walaog
///////////////////////////////////////////////////////////
HINSTANCE hInst;
long OldWebProc;
HWND DlgHwnd;
LRESULT CALLBACK WebProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
VOID CALLBACK MyTimerProc(
HWND hwnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT idEvent, // timer identifier
DWORD dwTime // current system time
);
void Add_SysTray(HWND hDlg,int dwMessage)
{
NOTIFYICONDATA sysTray;
char stip[14];
LoadString(hInst,IDS_TRYTIP,stip,sizeof(stip));
sysTray.cbSize = sizeof(sysTray);
sysTray.hWnd = DlgHwnd; //receive message form hwnd
strcpy(sysTray.szTip, stip);
sysTray.uID = 10011;
sysTray.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_ICON1));
sysTray.uCallbackMessage = My_Tray_Message;
sysTray.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
switch (dwMessage)
{
case 1: //Icon_add
Shell_NotifyIcon(NIM_ADD,&sysTray);
break;
case 0: //Icon_delete
Shell_NotifyIcon(NIM_DELETE,&sysTray);
break;
case 2: //Icon_modify
Shell_NotifyIcon(NIM_MODIFY,&sysTray);
break;
}
}
// form proc
BOOL CALLBACK MainDlgProc(HWND hDlg, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
static HWND MinehWnd;
static UINT TimeId;
switch (uMsg)
{
case WM_CLOSE:
ShowWindow(hDlg,SW_MINIMIZE);
ShowWindow(hDlg,SW_HIDE);
Add_SysTray (hDlg,1);
break;
//click the minimize button
case WM_SYSCOMMAND:
if (wParam==SC_MINIMIZE)
{
ShowWindow(hDlg,SW_MINIMIZE);
ShowWindow(hDlg,SW_HIDE);
Add_SysTray (hDlg,1);
}
break;
// My define Message
case My_Tray_Message:
switch (LOWORD(lParam))
{
HMENU PopMenu;
case WM_LBUTTONUP:
Add_SysTray(hDlg,0);
ShowWindow(hDlg,SW_SHOWNORMAL);
break;
case WM_RBUTTONUP:
char Exit[5]={'0'};
char Show[5]={'0'};
char About[5]={'0'};
static HBITMAP show;
static HBITMAP exit;
static HBITMAP about;
POINT point;
show = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_SHOW));
exit = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_EXIT));
about = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_ABOUT));
// static HANDLE LoadImage(hInst,'ds',IMAGE_BITMAP,16,16,LR_LOADFROMFILE);
// MENUITEMINFO MenuItemInfo;
// MenuItemInfo.cbSize=sizeof (MENUITEMINFO);
// MenuItemInfo.fMask = MIIM_CHECKMARKS;
//SetMenuItemInfo(PopMenu,IDM_SHOW,FALSE,&MenuItemInfo);
LoadString(hInst,IDM_SHOW,Show,sizeof(Show));
LoadString(hInst,IDM_EXIT,Exit,sizeof(Exit));
LoadString(hInst,IDM_ABOUT,About,sizeof(About));
// SetWindowLong(PopMenu,GWL_EXSTYLE,ModifyMenu);
PopMenu=CreatePopupMenu();
AppendMenu(PopMenu,MF_STRING,IDM_EXIT,Exit);
AppendMenu(PopMenu,MF_STRING,IDM_SHOW,Show);
AppendMenu(PopMenu,MF_STRING,IDM_ABOUT,About);
//DeleteMenu(Menu,IDM_SHOW,MF_BYCOMMAND);
//ModifyMenu(PopMenu,IDM_SHOW,MF_BITMAP,IDM_SHOW,show);
SetMenuItemBitmaps(PopMenu,IDM_SHOW,MF_BYCOMMAND,show,show);
SetMenuItemBitmaps(PopMenu,IDM_EXIT,MF_BYCOMMAND,exit,exit);
SetMenuItemBitmaps(PopMenu,IDM_ABOUT,MF_BYCOMMAND,about,about);
GetCursorPos(&point);
SetForegroundWindow(hDlg);
TrackPopupMenu(PopMenu, TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_LEFTALIGN,
point.x, point.y, 0, hDlg, NULL);
PostMessage(hDlg,WM_NULL,0,0);
DestroyMenu(PopMenu);
break;
}
break;
case WM_INITDIALOG:
{
HICON WinIcon;
char caption[5];
DlgHwnd=hDlg; // public Dlg hwnd
SetFocus(GetDlgItem(hDlg,IDC_RUN));
WinIcon=LoadIcon(hInst,MAKEINTRESOURCE(IDI_ICON1));
SendMessage(hDlg, WM_SETICON, ICON_SMALL,(LPARAM)WinIcon);
SetWindowPos(hDlg,HWND_TOPMOST,0,0,0,0,3); //top window
LoadString(hInst,IDS_MINE,caption,sizeof(caption));
MinehWnd=FindWindow(caption,caption);
//sub_clase web_control
OldWebProc=GetWindowLong(GetDlgItem(hDlg,IDC_WEB),GWL_WNDPROC);
SetWindowLong(GetDlgItem(hDlg,IDC_WEB),GWL_WNDPROC,(long)WebProc);
}
break;
//static web_control color
case WM_CTLCOLORSTATIC:
if ((HWND) lParam==GetDlgItem(hDlg,IDC_WEB))
{
HDC WebHdc=GetDC(GetDlgItem(hDlg,IDC_WEB));
// HDC DlgHdc=GetDC(hDlg);
static HBRUSH brush=(HBRUSH)CreateSolidBrush(RGB(212,208,200));
WebHdc=(HDC)wParam;
SetTextColor(WebHdc,RGB(0,0,255));
SetBkMode(WebHdc,TRANSPARENT);
return (DWORD)brush;
DeleteObject(brush);
ReleaseDC(hDlg,WebHdc);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
{
char Find[10];
char cancel[10];
char Buff[10];
char MineCap[5];
LoadString(hInst,IDS_MINE,MineCap,sizeof(MineCap));
if(!FindWindow(MineCap,MineCap))
{
MessageBox(DlgHwnd,"Run winmine.exe before click","mine",MB_OK);
break;
}
ShowWindow(FindWindow(MineCap,MineCap),SW_SHOWNORMAL);
SetForegroundWindow(FindWindow(MineCap,MineCap));
LoadString(hInst,IDS_FINDM,Find,sizeof(Find));
LoadString(hInst,IDS_STOPM,cancel,sizeof(cancel));
GetDlgItemText(hDlg,IDOK,Buff,sizeof(Buff));
if (!strcmp(Find,Buff))
{
SetDlgItemText(hDlg,IDOK,cancel);
SetTimer(hDlg,TimeId,800,MyTimerProc);
}
else
{
SetDlgItemText(hDlg,IDOK,Find);
KillTimer(hDlg,TimeId);
}
}
break;
// click menu exit buttom
case IDM_EXIT:
char caption [7];
char alert [20];
LoadString(hInst,IDS_CAPTION,caption,sizeof(caption));
LoadString(hInst,IDS_ALERT,alert,sizeof(alert));
if (MessageBox(hDlg,alert,caption,
MB_YESNO | MB_ICONINFORMATION) == IDYES)
{
KillTimer(hDlg,TimeId);
Add_SysTray(hDlg,0); //delete systray_icon
EndDialog(hDlg,0);
}
break;
//show about message
case IDM_ABOUT:
//char caption[7];
char context[40];
LoadString(hInst,IDS_CONTEXT,context,sizeof(context));
LoadString(hInst,IDS_CAPTION,caption,sizeof(caption));
MessageBox(hDlg,context,caption,MB_OK);
break;
//click show menu show the form
case IDM_SHOW:
Add_SysTray(hDlg,0);
ShowWindow(hDlg,SW_SHOWNORMAL);
break;
case IDCANCEL:
{
char title[5];
LoadString(hInst,IDS_MINE,title,sizeof(title));
MinehWnd=FindWindow(title,title);
if (MinehWnd)
KillTimer(MinehWnd,1);
}
break;
case IDC_RUN:
char MineCap[5];
HWND MineHwnd;
LoadString(hInst,IDS_MINE,MineCap,sizeof(MineCap));
MineHwnd = FindWindow(MineCap,MineCap);
if (MineHwnd)
{
ShowWindow(MineHwnd,SW_SHOWNORMAL);
SetForegroundWindow(MineHwnd);
}
else
{
char SysDirectory[255];
GetSystemDirectory(SysDirectory,sizeof(SysDirectory));
strcat(SysDirectory,"\\winmine.exe");
if (WinExec(SysDirectory,SW_SHOWNORMAL)==ERROR_FILE_NOT_FOUND)
MessageBox(DlgHwnd,"No Find winmine.exe file","mine",MB_OK);
}
break;
case IDC_WEB:
char site[40];
LoadString(hInst,IDS_WEBSITE,site,sizeof(site));
ShellExecute(hDlg,"open","iexplore.exe",site,NULL,SW_SHOWNORMAL);
break;
}
break; //end case WM_COMMAND
}
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
hInst=hInstance;
HWND hwnd = FindWindow(NULL,"探雷者 by gym");
if (hwnd)
{
ShowWindow(hwnd,SW_NORMAL);
return 0;
}
// TODO: Place code here.
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1),
NULL, (DLGPROC) MainDlgProc);
return 0;
}
//time callback proc
void CALLBACK MyTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
//four memory address variable
int WidthAddress = 0x0;
int HeightAddress = 0x0;
//int MinesAddress = 0x0;
int CellBaseAddress = 0x0;
static int byWidth = 0; //WidthAddress data
static int byHeight = 0; //HeightAddress data
static int byMines = 0; //MinesAddress data
static HANDLE hMine = 0; //mine process handle
char MineCap[5];
DWORD MineProID;
HWND MineHwnd=NULL;
LoadString(hInst,IDS_MINE, MineCap,sizeof(MineCap));
MineHwnd = FindWindow(MineCap,MineCap);
OSVERSIONINFO versionInfo;
versionInfo.dwOSVersionInfoSize =sizeof(versionInfo);
GetVersionEx( & versionInfo );
switch (versionInfo.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT:
if ( versionInfo.dwMajorVersion == 5)
{
if ( versionInfo.dwMinorVersion == 0 )
{
WidthAddress = 0x10056F8;
HeightAddress = 0x1005A68;
// MinesAddress = 0x1005A6C;
CellBaseAddress = 0x1005721;
// MessageBox(NULL,"win2000 system","system",0);
}
if ( versionInfo.dwMinorVersion == 1 )
{
WidthAddress = 0x1005334;
HeightAddress = 0x1005338;
// MinesAddress = 0x1005330;
CellBaseAddress = 0x1005361;
// MessageBox(NULL,"windows XP system","system",0);
}
}
break;
}
GetWindowThreadProcessId(MineHwnd,&MineProID);
hMine = OpenProcess(PROCESS_VM_READ , TRUE, MineProID);
if (hMine)
{
ReadProcessMemory(hMine, ( LPVOID ) WidthAddress,
& byWidth, 1, NULL); // read mine sum width
ReadProcessMemory(hMine,( LPVOID ) HeightAddress,
& byHeight,1,NULL); //read mine sum height
// ReadProcessMemory( hMine, & MinesAddress,
// &byMines, 1, NULL);
for ( int y = 0; y < byHeight; y++ )
{ //MessageBox(NULL,"fda","fda",0);
for ( int x = 0; x < byWidth; x++ )
{
int nMineCellAddress = CellBaseAddress + x + (y * 32) ;
ReadProcessMemory(hMine, ( LPVOID ) MineCellAddress,
& byMines, 1, NULL);
if (byMines==0x8F)
{
HDC hdc=GetDC(MineHwnd);
// MessageBox(NULL,"fda","fda",0);
SetTextColor(hdc,RGB(0,0,0));
SetBkMode(hdc,TRANSPARENT);
TextOut(hdc, x*16+13 , y*16+55 ,"雷",2);
ReleaseDC(MineHwnd,hdc);
}
} //end
} //end for
CloseHandle( hMine );
}
//enddialgo
}
//sub class web_control callback proc
LRESULT CALLBACK WebProc(HWND hwnd, UINT uMsg,WPARAM wParam,LPARAM lParam )
{
switch (uMsg)
{
case WM_MOUSEMOVE:
SetCursor(LoadCursor(hInst,MAKEINTRESOURCE(IDC_HAND)));
break;
}
return CallWindowProc((WNDPROC)OldWebProc, hwnd,uMsg,wParam,lParam);
}
posted on 2006-06-19 02:29
gym 阅读(1195)
评论(15) 编辑 收藏 引用