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

📄 zg1dlg.cpp

📁 模拟连连看看的程序源代码。 可运行的。
💻 CPP
字号:
// zg1Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "zg1.h"
#include "zg1Dlg.h"
#include"fstream.h"
#include"math.h"
#include"findpath.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
bool flagx=true;
int timecount;
int point1x,point1y,point2x,point2y;
struct MYCOLOR
{
	COLORREF c[4];
};
MYCOLOR tc[230];
int tcnum;
int map[19][11];
int r1,g1,b1,r2,b2,g2;
int pop1,pop2;


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()

/////////////////////////////////////////////////////////////////////////////
// CZg1Dlg dialog

CZg1Dlg::CZg1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CZg1Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CZg1Dlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	yyy=0;
}

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

BEGIN_MESSAGE_MAP(CZg1Dlg, CDialog)
	//{{AFX_MSG_MAP(CZg1Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_WM_TIMER()
	ON_WM_LBUTTONDOWN()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CZg1Dlg message handlers

BOOL CZg1Dlg::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
	SetTimer(2,100,NULL);
	CRect r;
	this->GetWindowRect(&r);
	::SetWindowPos(this->m_hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOREPOSITION|SWP_NOSIZE);
	::MoveWindow(this->m_hWnd,200,0,r.Width(),r.Height(),false);
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CZg1Dlg::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 CZg1Dlg::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 CZg1Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CZg1Dlg::OnButton1() 
{
	// TODO: Add your control notification handler code here

	CWnd *p=CWnd::FindWindow(NULL,"QQ连连看");
	if(p==NULL)
	{
		MessageBox("请启动连连看游戏窗口");
		return;
	}
	else
	{
		myc=p;
		MessageBox("锁定成功");
		return;
	}
	return;

	SetTimer(1,1000,NULL);
	ist=false;
    yyy++;    
}

void CZg1Dlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
    static int i=0;
	if(nIDEvent==1)
	{
	i++;
	if(i==5)
	{
		i=0;
		CPoint point;
		::GetCursorPos(&point);
        CWnd *p=WindowFromPoint( point);
    	if(p==NULL)
		   MessageBox("failed!");
    	else 
		{
		   CRect r;
		   p->GetClientRect(&r);
		   CString cs,cs1;
		   p->GetWindowText(cs1);
		   cs.Format("ok!!!%d,%d,%d",r.Width(),r.Height(),yyy);
		   cs=cs1;
		   MessageBox(cs);
		   myc=p;
		}
		ist=true;
     	KillTimer(1);	
	}
	}
	else if(nIDEvent==1000)
	{	
	}
	CDialog::OnTimer(nIDEvent);
}

void CZg1Dlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CDialog::OnLButtonDown(nFlags, point);
}

void CZg1Dlg::OnButton2() 
{	
      ::SetCursorPos(pop1,pop2);
      mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP,0,0,0,0);
}

int cha(COLORREF a,COLORREF b)
{
	
	r1=GetRValue(a);
	r2=GetRValue(b);
	g1=GetGValue(a);
	g2=GetGValue(b);
	b1=GetBValue(a);
	b2=GetBValue(b);
    return abs(r1-r2)+abs(g1-g2)+abs(b1-b2);
}
int findcolor(MYCOLOR &m)
{
	for(int i=0;i<tcnum;i++)
	{
		if( cha(tc[i].c[0],m.c[0])+cha(tc[i].c[1],m.c[1])+
			cha(tc[i].c[2],m.c[2])+cha(tc[i].c[3],m.c[3])<15)
             return i;
	}
	return -1;
}
void CZg1Dlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	int pnum=0;
	//////////////////
	int t[4]={15,11,15,21};
	int tt[4]={17,17,21,17};
	////////////////////
	int result;
    tc[0].c[0]=tc[0].c[1]=tc[0].c[2]=tc[0].c[3]=7753015;
	tcnum=1;
	MYCOLOR tmp;
	CPoint p(10,180);
	
	CDC *pdc=myc->GetDC();
	CString hh="     编码结果: \n";
	CString h;
	int myr,myg,myb,t_t,sh;
	for(int i=0;i<11;i++)
	{
		p.y=180+i*35;
		for(int j=0;j<19;j++)
		{
			p.x=10+j*31;
			for(int k=0;k<4;k++)
				tmp.c[k]=pdc->GetPixel(p.x+t[k],p.y+tt[k]);
			
			
			sh=0;
			for(t_t=0;t_t<4;t_t++)
			{
			    myr=GetRValue(tmp.c[t_t]);
		    	myg=GetGValue(tmp.c[t_t]);
		    	myb=GetBValue(tmp.c[t_t]);
				if ( (myr<73) &&(myr>45) &&(myg>50) &&(myg<90) &&(myb>103) &&(myb<129) ) 
					sh++;
			}
			if(sh==4)
					map[j][i]=0;
			
			else
			{
				pnum++;
			     result=findcolor(tmp);
			     if(result==-1)
				 {
				tc[tcnum].c[0]=tmp.c[0];
				tc[tcnum].c[1]=tmp.c[1];
				tc[tcnum].c[2]=tmp.c[2];
				tc[tcnum].c[3]=tmp.c[3];
			    	map[j][i]=tcnum;
			     	tcnum++;	
				 }
		    	else
				{
                   map[j][i]=result;
				}
			}
			h.Format("%d ",map[j][i]);
            hh+=h;
			sh=0;
		}
		hh+="\n";
	}


	bool yy=true;
	for(int y1=0;y1<11;y1++)
	{
		for(int y2=0;y2<19;y2++)
		{
            if(tc[map[y2][y1]].c[0]==-1)
			    yy=false;
		}
	}

	CString cs2;
	cs2.Format("总共有 %d 可消!",pnum);
	hh+=cs2;
    MessageBox(hh);
	for(i=0;i<11;i++)
		for(int j=0;j<19;j++)
		{
			mymap[i][j]=map[j][i];
		}

	if(!yy)
	{
		MessageBox("请重新编码!\n编码时要确保游戏窗口不要被其他窗口挡住!");  
	}
      flagx=true;
}

void CZg1Dlg::OnButton7() 
{
                CRect r;
                this->GetClientRect(&r);
                this->ClientToScreen(&r);
			    CRect r1;
                myc->GetClientRect(&r1);
                myc->ClientToScreen(&r1);
		if(flagx)
		{	   
			flagx=!flagx;
		    if (mystart(point1x,point1y,point2x,point2y))
			{
                ::SetCursorPos(point1x*31+8+r1.left+15,point1y*35+180+r1.top+17);
                mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP,0,0,0,0);
                pop1=point2x*31+8+r1.left+15;
               	pop2=point2y*35+180+r1.top+17;
                ::SetCursorPos(247+r.left,23+r.top);
			}
		}
		else
		{
                flagx=!flagx;
                ::SetCursorPos(point2x*31+8+r1.left+15,point2y*35+180+r1.top+17);
                mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP,0,0,0,0);
               // ::SetCursorPos(pop1,pop2);
                //mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP,0,0,0,0);
                mymap[point1y][point1x]=mymap[point2y][point2x]=0;
		        map[point1x][point1y]=map[point2x][point2y]=0;
                ::SetCursorPos(247+r.left,23+r.top);
		}
}

void CZg1Dlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
	CString cs;
//	cs="注意: \n0.在任何时候都不要点击单击按钮\n1.先启动本程序,和QQ连连看游戏窗口.\n2.点锁定按钮,然后在5秒内移动鼠标到QQ连连看游戏窗口\n3.成功锁定会有ok消息,不成功请重新锁定\n4.当玩游戏时点编码按钮\n5.成功后点击消去按钮,每点2次消去1对.\n6.作者:第一高手\n7.QQ:330549510 \n";
   	cs="注意: \n1.先启动本程序,和QQ连连看游戏窗口.\n2.点锁定按钮\n3.成功锁定会有锁定成功消息,不成功请重新锁定\n4.当玩游戏时点编码按钮,可对当前图形编码\n5.成功后点击消去按钮,每点2次消去1对.\n6.作者:第一高手\n7.QQ:330549510 \n";
	MessageBox(cs,"help");

}

⌨️ 快捷键说明

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