📄 crackwinminedlg.cpp
字号:
// CrackWinMineDlg.cpp : implementation file
//
/*
* 自动扫雷机 v1.0
* Made By : cngdzhang
* Revised By : Zhai Yanhui
* 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()
//////////////////////////////////////////////////////////
//******revised by zyh
BOOL isInWin98;
DWORD dwVersion;
DWORD dwWindowsMajorVersion;
DWORD dwWindowsMinorVersion;
DWORD dwBuild;
CString winMineClassName;
CString failureMsg;
CString successMsg;
CString hintMsg;
CString errMsg;
CString iconicMsg;
int sleepTime;
int i=0;
HWND hWnd=NULL;
UINT beginMine( LPVOID pParam )
{
CCrackWinMineDlg* pDlg=(CCrackWinMineDlg*)pParam;
sleepTime=pDlg->m_spin.GetPos();
if(hWnd==NULL)
{
hWnd=::FindWindow(winMineClassName,NULL);
if(!hWnd)
{
if(::MessageBox(NULL,hintMsg,NULL,MB_YESNO | MB_ICONQUESTION)==IDYES)
{
if((int)::ShellExecute(NULL,NULL,"WinMine.exe",NULL,NULL,SW_SHOWNORMAL)>32)
{
while(!hWnd) hWnd=::FindWindow(winMineClassName,NULL);
}
else
{
::MessageBox(NULL,errMsg,NULL,MB_OK | MB_ICONERROR);
return 0;
}
}
else
{
return 0;
}
}
if(::IsIconic(hWnd))
{
::MessageBox(NULL,iconicMsg,NULL,MB_OK | MB_ICONINFORMATION);
::ShowWindow(hWnd,SW_SHOWNORMAL);
}
::BringWindowToTop(hWnd);
::SetActiveWindow(hWnd);
}
CRect rect;
::GetClientRect(hWnd,&rect);
if(isInWin98)
{
pDlg->width=(rect.right-rect.left-24)/16;
pDlg->height=(rect.bottom-rect.top-67)/16;
}
else
{
pDlg->width=(rect.right-rect.left-20)/16;
pDlg->height=(rect.bottom-rect.top-63)/16;
}
pDlg->resetData();
::PostMessage(hWnd,WM_KEYDOWN,VK_F2,0);
pDlg->selOneToClick();
while(1)
{
if(pDlg->bSet) return 0;
Sleep(sleepTime*7);
if(isInWin98) pDlg->scanTheMap98();
else pDlg->scanTheMap();
pDlg->makeDecision();
Sleep(sleepTime*7);
if(isInWin98) pDlg->scanTheMap98();
else pDlg->scanTheMap();
if(pDlg->finish)
{
CString strC,str;
strC.Format("第%d 次 :",i);
pDlg->m_edit.GetWindowText(str);
pDlg->m_edit.SetWindowText(str+"\r\n"+strC+successMsg);
pDlg->bSucc=true;
pDlg->state=SUCCESS;
i++;
return 0;
}
if(pDlg->state==FAILURE)
{
CString str,strC;
strC.Format("第%d 次 :",i);
pDlg->m_edit.GetWindowText(str);
pDlg->m_edit.SetWindowText(str+"\r\n"+strC+failureMsg);
::PostMessage(hWnd,WM_KEYDOWN,VK_F2,0);
i++;
break;
}
if(pDlg->state==NOCHANGE)
{
/*屏蔽了:(
if(needAdv)
pDlg->advanceDecision();
// else selOneToClick();
// */
pDlg->selOneToClick();
}
}
}
///////////////////////////////////////////
//added by zyh
UINT beginMines( LPVOID pParam )
{
CCrackWinMineDlg* pDlg=(CCrackWinMineDlg*)pParam;
while(!pDlg->bSucc)
{
beginMine(pParam);
if(pDlg->bSet) return 0;
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CCrackWinMineDlg dialog
CCrackWinMineDlg::CCrackWinMineDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCrackWinMineDlg::IDD, pParent)
{
bSet=false;
bSucc=false;
//{{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, IDC_EDIT1, m_edit);
DDX_Control(pDX, IDCANCEL, m_exit);
DDX_Control(pDX, IDC_ABOUT, m_about);
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_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)
ON_BN_CLICKED(IDC_START2, OnStart2)
ON_BN_CLICKED(IDC_START3, OnStart3)
ON_BN_CLICKED(IDC_START4, OnStart4)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCrackWinMineDlg message handlers
BOOL CCrackWinMineDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CRichEditCtrl().SetEventMask(ENM_CHANGE);
// 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()
{///////////////////////////////////////
///revised by zyh 转为线程
m_edit.SetWindowText("");
CWinThread* m_Thread=AfxBeginThread( beginMine, (LPVOID)this);
//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])
{
map[i][j]=k+1;
found=TRUE;
break;
}
}
if(!found)
{
c=::GetPixel(hDC,p.x+1,p.y);
if(c==color[6])
{
map[i][j]=7;
}
else
{
c=::GetPixel(hDC,p.x-7,p.y-7);
if(c==RGB(255,255,255))
{
}
else
{
map[i][j]=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -