刺激战场
六合彩
贵宾厅
  • 1685阅读
  • 1回复

2.3.使用VC制作连连看 [复制链接]

上一主题 下一主题
离线啊冲
 

只看楼主 倒序阅读 使用道具 楼主  发表于: 2015-10-25

// LLKAuxiliaryDlg.cpp : implementation file
//

#include "stdafx.h"
#include "LLKAuxiliary.h"
#include "LLKAuxiliaryDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLLKAuxiliaryDlg dialog

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

void CLLKAuxiliaryDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CLLKAuxiliaryDlg)
    DDX_Text(pDX, IDC_EDIT_Str, m_Str);
    DDX_Text(pDX, IDC_EDIT_ChessData, m_szChessData);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CLLKAuxiliaryDlg, CDialog)
    //{{AFX_MSG_MAP(CLLKAuxiliaryDlg)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_BUTTON_GetWindow, OnBUTTONGetWindow)
    ON_BN_CLICKED(IDC_BUTTON_StartGame, OnBUTTONStartGame)
    ON_BN_CLICKED(IDC_BUTTON_ReadChessData, OnBUTTONReadChessData)
    ON_BN_CLICKED(IDC_BUTTON_ReadSeatNum, OnBUTTONReadSeatNum)
    ON_BN_CLICKED(IDC_BUTTON_ClickChess, OnBUTTONClickChess)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLLKAuxiliaryDlg message handlers

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

    // 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
    
    return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CLLKAuxiliaryDlg::OnBUTTONGetWindow()
{
    // TODO: Add your control notification handler code here
    WCHAR szBuffer[255] = {0};
    //找到窗体
    HWND gameh = ::FindWindow(NULL,L"QQ游戏 - 连连看角色版");
    wsprintf(szBuffer,L"窗体句柄:%08X",gameh);
    m_Str = szBuffer;
    //TRUE 是更新窗体数据到内存
    //FALSE 是更新数据到窗体
    this->UpdateData(FALSE);
    return;
}

void CLLKAuxiliaryDlg::OnBUTTONStartGame()
{
    // TODO: Add your control notification handler code here
    RECT r1;
    POINT OldP;
    //找到窗体
    HWND gameh = ::FindWindow(NULL,L"QQ游戏 - 连连看角色版");
    //设置窗体属性
    ::SetWindowPos(gameh,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
    //得到窗体位置
    ::GetWindowRect(gameh,&r1);
    //656 567
    //保存原始鼠标位置
    GetCursorPos(&OldP);
    //设置鼠标位置
    SetCursorPos(r1.left+656,r1.top+567);
    //模拟鼠标单击事件
    //抬起
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
    //压下
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
    //抬起
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
    //休息一下
    Sleep(200);
    //还原鼠标原始位置
    SetCursorPos(OldP.x,OldP.y);
    return;
}

void CLLKAuxiliaryDlg::OnBUTTONReadChessData()
{
    // TODO: Add your control notification handler code here
    DWORD Processid;
    HANDLE processh;
    BYTE LLKChessdata[11][19]={0};
    //让Buffer指向数组,操作指针就是操作数组
    LPVOID lpBuffer = (LPVOID)&LLKChessdata;
    DWORD bybyte;
    WCHAR szBuffer[255]={0};
    BYTE *pTemp = NULL;
    //找到窗体
    HWND gameh = ::FindWindow(NULL,L"QQ游戏 - 连连看角色版");
    //得到进程PID
    ::GetWindowThreadProcessId(gameh,&Processid);
    //打开指定进程
    processh = OpenProcess(PROCESS_ALL_ACCESS,FALSE,Processid);
    //读指定进程内存数据
    ReadProcessMemory(processh,(LPCVOID)0x0012A480,lpBuffer,11*9,&bybyte);
    m_szChessData = L"";
    //Temp指向整理好的内存起始位置
    pTemp = (BYTE*)lpBuffer;
    //0x0012A480
    for (int y=0;y<=10;y++)
    {
        for (int x=0;x<=18;x++)
        {
            //自言自语一遍
            LLKChessdata[y][x]=*pTemp;
            //格式化字符串
            wsprintf(szBuffer,L"%02X",LLKChessdata[y][x]);
            m_szChessData += szBuffer;
            m_szChessData += L" ";
            //推进指针
            pTemp++;
        }
        //换一行
        m_szChessData += L"\r\n";
    }
    //更新内容到窗体
    this->UpdateData(FALSE);
    return;
}

void CLLKAuxiliaryDlg::OnBUTTONReadSeatNum()
{
    // TODO: Add your control notification handler code here
    DWORD Temp;
    DWORD Processid;
    HANDLE processh;
    DWORD bybyte;
    DWORD dwSeatNum =0;
    WCHAR szBuffer[255]={0};

    //dd [0x4D2464]+0x434+0x2c
    //找到窗体
    HWND gameh = ::FindWindow(NULL,L"QQ游戏 - 连连看角色版");
    //得到进程PID
    ::GetWindowThreadProcessId(gameh,&Processid);
    //打开指定进程
    processh = OpenProcess(PROCESS_ALL_ACCESS,FALSE,Processid);
    //读指定进程内存数据
    ReadProcessMemory(processh,(LPCVOID)0x4D2464,(LPVOID)&Temp,4,&bybyte);
    if (IsBadReadPtr((LPVOID)Temp,0x4) == FALSE)
    {
        OutputDebugString(L"OnBUTTONReadSeatNum:读取地址是无效的");
        return;
    }
    ReadProcessMemory(processh,(LPCVOID)(Temp+0x434+0x2c),&dwSeatNum,4,&bybyte);
    if (IsBadReadPtr((LPVOID)dwSeatNum,0x4) == FALSE)
    {
        OutputDebugString(L"OnBUTTONReadSeatNum:读取地址是无效的");
        return;
    }
    wsprintf(szBuffer,L"座位号:%d",dwSeatNum);
    m_Str = szBuffer;
    this->UpdateData(FALSE);
    return;
}

void CLLKAuxiliaryDlg::OnBUTTONClickChess()
{
    // TODO: Add your control notification handler code here
    //X长度是600像素,Y高度是390像素
    //每个棋子长度32像素,每个棋子高度36像素
    int ChessHeight = 36;
    int ChessWidth = 32;
    //找到窗体
    HWND gameh = ::FindWindow(NULL,L"QQ游戏 - 连连看角色版");
    //第一个棋子的中心21,192
    int x=21,y=192;
    int ylparam=y;
    int xlparam=x;
    int ChessNum =0; //棋子号
    ::SendMessage(gameh,WM_LBUTTONDOWN,0,((ylparam+ChessNum*ChessHeight)<<16)+xlparam);
    ::SendMessage(gameh,WM_LBUTTONUP,0,((ylparam+ChessNum*ChessHeight)<<16)+xlparam);
    return;
}
善者 慈悲心常在 无怨无恨 以苦为乐
默认压缩密码www.hifyl.com
文件分享密码问题:http://www.hifyl.com/read-htm-tid-4444.html
离线yelochina

只看该作者 沙发  发表于: 2015-11-01
下载学习
快速回复
限100 字节
如果您在写长篇帖子又不马上发表,建议存为草稿
 
上一个 下一个