CQQFindDlg.cpp
资源名称:CQQFind.rar [点击查看]
上传用户:cxh888fhc
上传日期:2017-07-08
资源大小:240k
文件大小:7k
源码类别:
钩子与API截获
开发平台:
Visual C++
- // CQQFindDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "CQQFind.h"
- #include "CQQFindDlg.h"
- #include "QQBitmap.h"
- #include "ConfigDlg.h"
- #include "AboutDlg.h"
- #include <afxtempl.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CCQQFindDlg dialog
- CCQQFindDlg::CCQQFindDlg(CWnd* pParent /*=NULL*/)
- : CBitmapDialog(CCQQFindDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CCQQFindDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CCQQFindDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CCQQFindDlg)
- DDX_Control(pDX, IDC_BTN_CONFIG, m_btnConfig);
- DDX_Control(pDX, IDC_BTN_ABOUT, m_btnAbout);
- DDX_Control(pDX, IDCANCEL, m_btnCancel);
- DDX_Control(pDX, IDC_BTN_TEST, m_btnTest);
- DDX_Control(pDX, IDC_BTN_CLOSE, m_btnClose);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CCQQFindDlg, CBitmapDialog)
- //{{AFX_MSG_MAP(CCQQFindDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BTN_TEST, OnBtnTest)
- ON_BN_CLICKED(IDC_BTN_CLOSE, OnBtnClose)
- ON_BN_CLICKED(IDC_BTN_CONFIG, OnBtnConfig)
- ON_BN_CLICKED(IDC_BTN_ABOUT, OnBtnAbout)
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CCQQFindDlg message handlers
- BOOL CCQQFindDlg::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
- LoadBitmap(IDB_BITMAP2);//加载位图
- SetTransparent (TRUE);
- SetTransColor (RGB(0,0,0));//去掉形状的颜色设置
- SetStaticTransparent (TRUE);
- SetClickAnywhereMove (TRUE);//鼠标是否能拖动窗体。
- m_btnCancel.SetDefaultButton(TRUE);
- m_btnClose.SetDefaultButton(TRUE);
- m_btnTest.SetDefaultButton(TRUE);
- m_btnAbout.SetDefaultButton(TRUE);
- m_btnConfig.SetDefaultButton(TRUE);
- m_btnCancel.SetDefaultFace();
- m_btnClose.SetDefaultFace();
- m_btnTest.SetDefaultFace();
- m_btnAbout.SetDefaultFace();
- m_btnConfig.SetDefaultFace();
- if(GetFileAttributes("QQFind.whj")==-1)
- {
- //文件不存在
- CFile file("QQFind.whj",CFile::modeCreate|CFile::modeReadWrite);
- CArchive ar(&file,CArchive::store);
- ar<<RGB(0,0,255);
- ar<<TRUE;
- ar<<3;
- ar.Close();
- file.Close();
- }
- CFile file("QQFind.whj",CFile::modeRead);
- CArchive ar(&file,CArchive::load);
- ar>>m_clrDraw;
- ar>>m_bCircle;
- ar>>m_nWidth;
- ar.Close();
- file.Close();
- 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 CCQQFindDlg::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 CCQQFindDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CCQQFindDlg::OnBtnTest()
- {
- // TODO: Add your control notification handler code here
- if(m_dlgFlag.m_hWnd)
- {
- m_dlgFlag.DestroyWindow();
- m_dlgFlag.m_arrayDif.RemoveAll();
- m_dlgFlag.m_rcRegion.left=m_dlgFlag.m_rcRegion.right=
- m_dlgFlag.m_rcRegion.top=m_dlgFlag.m_rcRegion.bottom=-1;
- }
- HWND hWnd=::FindWindow("#32770","大家来找茬");
- if(hWnd==NULL)
- {
- MessageBox("没有开启QQ游戏","错误提示",MB_ICONWARNING);
- return;
- }
- CQQBitmap bmp(hWnd);
- CArray<RECT,RECT> arrayDif;
- RECT rcP1;
- bmp.GetDiffRects(arrayDif);
- bmp.GetPicture1Rect(rcP1);
- m_dlgFlag.m_rcRegion=rcP1;
- int nCount=arrayDif.GetSize();
- for(int i=0;i<nCount;i++)
- {
- RECT rcTemp;
- rcTemp=arrayDif.GetAt(i);
- m_dlgFlag.m_arrayDif.Add(rcTemp);
- }
- m_dlgFlag.Create(IDD_DLG_FLAG,this);
- m_dlgFlag.ShowWindow(SW_SHOW);
- SetTimer(1,10,NULL);
- //窗口显示出来之后,会获得焦点,引起游戏窗口不活动,从而可能导致
- //标识窗口显示不出来,因此设置一个时钟,立即将游戏窗口激活.
- }
- void CCQQFindDlg::OnBtnClose()
- {
- // TODO: Add your control notification handler code here
- if(m_dlgFlag.m_hWnd)
- {
- m_dlgFlag.DestroyWindow();
- m_dlgFlag.m_arrayDif.RemoveAll();
- m_dlgFlag.m_rcRegion.left=m_dlgFlag.m_rcRegion.right=
- m_dlgFlag.m_rcRegion.top=m_dlgFlag.m_rcRegion.bottom=-1;
- }
- }
- void CCQQFindDlg::OnCancel()
- {
- // TODO: Add extra cleanup here
- SetWindowLong(m_hWnd,GWL_EXSTYLE,
- GetWindowLong(m_hWnd,GWL_EXSTYLE)|0x80000);
- HINSTANCE hInst = LoadLibrary("User32.DLL");
- if(hInst)
- {
- typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
- MYFUNC fun = NULL;
- fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
- if(fun)
- {
- int i=255*3;
- {
- while(i--)
- {
- MSG msg;
- while(PeekMessage(&msg,m_hWnd,0,0,PM_REMOVE))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- fun(m_hWnd,0,i/3,2);
- }
- }
- }
- FreeLibrary(hInst);
- }
- CBitmapDialog::OnCancel();
- }
- void CCQQFindDlg::OnOK()
- {
- }
- void CCQQFindDlg::OnBtnConfig()
- {
- // TODO: Add your control notification handler code here
- CConfigDlg dlg;
- if(IDOK==dlg.DoModal())
- {
- m_clrDraw=dlg.m_clrDraw;
- m_bCircle=dlg.m_nCirCle==0?TRUE:FALSE;
- m_nWidth=dlg.m_nWidth;
- CFile file("QQFind.whj",CFile::modeCreate|CFile::modeReadWrite);
- CArchive ar(&file,CArchive::store);
- ar<<m_clrDraw;
- ar<<m_bCircle;
- ar<<m_nWidth;
- ar.Close();
- file.Close();
- m_dlgFlag.Invalidate(TRUE);
- }
- }
- void CCQQFindDlg::OnBtnAbout()
- {
- // TODO: Add your control notification handler code here
- CAboutDlg dlg;
- dlg.DoModal();
- }
- void CCQQFindDlg::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- KillTimer(1);
- HWND hWnd=::FindWindow("#32770","大家来找茬");
- if(hWnd==NULL)
- {
- return;
- }
- //激活游戏窗口,同时会将标识窗口显示到顶端
- ::SetWindowPos(hWnd,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
- CBitmapDialog::OnTimer(nIDEvent);
- }