⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crackwinminedlg.cpp

📁 自动扫雷机 v1.0 1.双语版(中文,英文),能自动检测操作系统版本和语言,采用相应的界面和扫雷规则 2.可以自动完成扫雷过程, 在Athlon 1G上的最好成绩为: 初级:1秒 中级:1秒 高级:
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// CrackWinMineDlg.cpp : implementation file
//
/*
*   自动扫雷机 v1.0
*   Made By : cngdzhang
*   Date    : 2004.2
*
*/

#include "stdafx.h"
#include "CrackWinMine.h"
#include "CrackWinMineDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCrackWinMineDlg dialog

CCrackWinMineDlg::CCrackWinMineDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCrackWinMineDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCrackWinMineDlg)
	m_winver = _T("");
	m_language = _T("");
	m_ms = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCrackWinMineDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCrackWinMineDlg)
	DDX_Control(pDX, IDCANCEL, m_exit);
	DDX_Control(pDX, IDC_ABOUT, m_about);
	DDX_Control(pDX, IDC_STATIC_INFO, m_info);
	DDX_Control(pDX, IDC_STATIC_WAIT, m_wait);
	DDX_Control(pDX, IDC_STATIC_TIMER, m_timer);
	DDX_Control(pDX, IDC_SPIN, m_spin);
	DDX_Control(pDX, IDC_SLIDER_SPEED, m_speed);
	DDX_Control(pDX, IDC_STOPTIME, m_stoptime);
	DDX_Control(pDX, IDC_START, m_start);
	DDX_Text(pDX, IDC_EDIT, m_sleeptime);
	DDV_MinMaxInt(pDX, m_sleeptime, 20, 1000);
	DDX_Text(pDX, IDC_STATIC_FAST, m_fast);
	DDX_Text(pDX, IDC_STATIC_SLOW, m_slow);
	DDX_Text(pDX, IDC_STATIC_WINVER, m_winver);
	DDX_Text(pDX, IDC_STATIC_LAN, m_language);
	DDX_Text(pDX, IDC_STATIC_MS, m_ms);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCrackWinMineDlg, CDialog)
	//{{AFX_MSG_MAP(CCrackWinMineDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_BN_CLICKED(IDC_STOPTIME, OnStopTime)
	ON_WM_TIMER()
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER_SPEED, OnReleasedcaptureSliderSpeed)
	ON_BN_CLICKED(IDC_ABOUT, OnAbout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCrackWinMineDlg message handlers

BOOL CCrackWinMineDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here

	srand((unsigned)time(NULL));
	rand();

	color[0]=RGB(0,0,255);
	color[1]=RGB(0,128,0);
	color[2]=RGB(255,0,0);
	color[3]=RGB(0,0,128);
	color[4]=RGB(128,0,0);
	color[5]=RGB(0,128,128);
	color[6]=RGB(0,0,0);
	color[7]=RGB(128,128,128);

	pos[0][0]=-1;	pos[0][1]=-1;
	pos[1][0]=0;	pos[1][1]=-1;
	pos[2][0]=1;	pos[2][1]=-1;
	pos[3][0]=1;	pos[3][1]=0;
	pos[4][0]=1;	pos[4][1]=1;
	pos[5][0]=0;	pos[5][1]=1;
	pos[6][0]=-1;	pos[6][1]=1;
	pos[7][0]=-1;	pos[7][1]=0;

	m_speed.SetRange(1,2000,TRUE);
	m_speed.SetPos(1000);

	m_spin.SetRange(20,1000);
	m_spin.SetBuddy(GetDlgItem(IDC_EDIT));
	m_spin.SetPos(30);

	getWinVer();
	getWinLan();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCrackWinMineDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CCrackWinMineDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		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;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CCrackWinMineDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CCrackWinMineDlg::OnStart() 
{
	// TODO: Add your control notification handler code here

	sleepTime=m_spin.GetPos();

	hWnd=::FindWindow(winMineClassName,NULL);
	if(!hWnd)
	{
		if(MessageBox(hintMsg,NULL,MB_YESNO | MB_ICONQUESTION)==IDYES)
		{
			if((int)::ShellExecute(m_hWnd,NULL,"WinMine.exe",NULL,NULL,SW_SHOWNORMAL)>32)
			{
				while(!hWnd) hWnd=::FindWindow(winMineClassName,NULL);
			}
			else
			{
				MessageBox(errMsg,NULL,MB_OK | MB_ICONERROR);
				return;
			}
		}
		else
		{
			return;
		}
	}
	if(::IsIconic(hWnd))
	{
		MessageBox(iconicMsg,NULL,MB_OK | MB_ICONINFORMATION);
		::ShowWindow(hWnd,SW_SHOWNORMAL);
	}
	::BringWindowToTop(hWnd);
	::SetActiveWindow(hWnd);

	CRect rect;
	::GetClientRect(hWnd,&rect);
	if(isInWin98)
	{
		width=(rect.right-rect.left-24)/16;
		height=(rect.bottom-rect.top-67)/16;
	}
	else
	{
		width=(rect.right-rect.left-20)/16;
		height=(rect.bottom-rect.top-63)/16;
	}

	resetData();
	::PostMessage(hWnd,WM_KEYDOWN,VK_F2,0);

	selOneToClick();

	while(1)
	{
		Sleep(sleepTime);
		if(isInWin98) scanTheMap98();
		else scanTheMap();
		makeDecision();
		Sleep(sleepTime);
		if(isInWin98) scanTheMap98();
		else scanTheMap();
		if(finish)
		{
			MessageBox(successMsg,NULL,MB_OK | MB_ICONINFORMATION);
			state=SUCCESS;
			return;
		}
		if(state==FAILURE)
		{
			MessageBox(failureMsg,NULL,MB_OK | MB_ICONINFORMATION);
			::PostMessage(hWnd,WM_KEYDOWN,VK_F2,0);
			break;
		}
		if(state==NOCHANGE)
		{
			/*屏蔽了:(
			if(needAdv) advanceDecision();
			else selOneToClick();
			*/
			selOneToClick();
		}
	}

	//CString s;
	//s.Format("行:%d   列:%d",(rect.right-rect.left-20)/16,(rect.bottom-rect.top-63)/16);
	//MessageBox(s);
	//::PostMessage(pWnd->m_hWnd,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM ((rect.left+rect.right)/2,rect.top+75));
	//右键::PostMessage(pWnd->m_hWnd,WM_RBUTTONDOWN,MK_RBUTTON,MAKELPARAM (83,89));
	//左键::PostMessage(pWnd->m_hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM (83,86));
	//左键::PostMessage(pWnd->m_hWnd,WM_LBUTTONUP,0,MAKELPARAM (83,86));
	//重新开始::PostMessage(pWnd->m_hWnd,WM_KEYDOWN,VK_F2,0);
	//双键::PostMessage(pWnd->m_hWnd,WM_LBUTTONDOWN,MK_LBUTTON | MK_RBUTTON,MAKELPARAM (83,89));
	//双键::PostMessage(pWnd->m_hWnd,WM_RBUTTONUP,0,MAKELPARAM (83,89));

}

void CCrackWinMineDlg::resetData()
{
	int i,j;
	for(i=0;i<=width+1;++i)
	{
		for(j=0;j<=height+1;++j)
		{
			if(i==0 || i==(width+1) || j==0 || j==(height+1)) map[i][j]=0;
			else map[i][j]=-1;
		}
	}
	needAdv=true;
	state=CHANGE;
}


void CCrackWinMineDlg::selOneToClick()
{

	int x,y;
	do
	{
		x=rand()%width+1;
		y=rand()%height+1;
	}while(map[x][y]!=-1);

	needAdv=true;

	x=13+(x-1)*16+7;
	y=56+(y-1)*16+7;
	::PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM (x,y));
	::PostMessage(hWnd,WM_LBUTTONUP,0,MAKELPARAM (x,y));
}


void CCrackWinMineDlg::scanTheMap()
{
	//13 56	//left top corner
	int i,j,k;
	CPoint p;
	COLORREF c;
	BOOL found;

	hDC=::GetDC(NULL);

	finish=TRUE;

	color[6]=RGB(0,0,0);
	color[7]=RGB(128,128,128);

	for(i=1;i<=width;++i)
	{
		for(j=1;j<=height;++j)
		{
			if(map[i][j]!=-1) continue;
			finish=FALSE;
			p.x=13+(i-1)*16+7;
			p.y=56+(j-1)*16+7;
			::ClientToScreen(hWnd,&p);
			c=::GetPixel(hDC,p.x-1,p.y-1);
			if(c==RGB(255,255,255))
			{
				//bomb
				state=FAILURE;
				return;
			}
			c=::GetPixel(hDC,p.x,p.y);
			found=FALSE;
			for(k=0;k<8;++k)
			{
				if(k==6) continue;
				if(c==color[k])
				{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -