對對碰鼠標點擊--隨機版

//定義客戶端和鼠標座標全局變量
int width,height,x,y,x00,y00;
HWND myhwnd;
//定義鼠標座標等信息
WINUSERAPI
VOID
WINAPI
mouse_event(
   DWORD dwFlags,
   DWORD dx,
   DWORD dy,
   DWORD dwData,
    DWORD dwExtraInfo);

//回調函數
BOOL   CALLBACK   EnumWindowsProc(
  HWND   hwnd,             //   handle   to   parent   window
  LPARAM   lParam       //   application-defined   value
   )
{
 char   lpWinTitle[256];  
 ::GetWindowText(hwnd,lpWinTitle,256-1);  
 CString   m_strTitle;
 myhwnd = hwnd;
 m_strTitle.Format( "%s",lpWinTitle);
// if(m_strTitle.Find( "QQ2011")!=-1)
 if(m_strTitle.Find( "對對碰角色版")!=-1)
 {
  ::ShowWindow(hwnd,SW_SHOWNORMAL);
  ::SetForegroundWindow(hwnd);
  CRect rect;
  GetWindowRect(hwnd,&rect);
        CString message;
  
  width=rect.Width();
  height=rect.Height();
     x00=rect.TopLeft().x;
  y00=rect.TopLeft().y;

//  message.Format("找到了酷狗音樂,(%d,%d)寬=%d;高=%d",x0,y0,width,height);

//  AfxMessageBox(message);
  return   FALSE;  
 }
 return   TRUE;  

}

 

void CMyDlg::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();
  CRect rect;
  CDC* dc=GetDC();
  GetClientRect(&rect); //計算對話框的尺寸
        dc->FillSolidRect(&rect,RGB(192,248,202)); //繪製對話框背景色
 }
}
void CMyDlg::OnStart()
{
 // TODO: Add your control notification handler code here

 EnumWindows((WNDENUMPROC)EnumWindowsProc,NULL);
 
 int i,j,k=0;
 //找茬算法
/* for(k=0;k<3;k++)
 {
 for(i=1;i<10;i++)
 {
  for(j=6;j<20;j++)
  {
   ::ShowWindow(myhwnd,SW_SHOWNORMAL);
         ::SetForegroundWindow(myhwnd);
   SetCursorPos(x0+width/400*i,y0+height/25*j);
   Sleep(1000);
   mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
   mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
  }
 }
 }*/
  //對對碰算法

 int t=48,m;
 int dir[8]={t,0,0,-t,0,t,-t,0};
 for(m=0;m<200;m++)
 {
  
// for(j=y00+110;j<=y00+442;)
// {
//  for(i=x00+280;i<=x00+624;) //264+24
//  {
   ::ShowWindow(myhwnd,SW_SHOWNORMAL);
            ::SetForegroundWindow(myhwnd);   
   for(k=0;k<4;k++)
   {
  //  k=rand()%4;
  //  j=rand()%7+3;i=rand()%8+5;
  //  srand((unsigned)time(NULL));
    i=rand()%8*48+x00+280;
    j=rand()%8*48+y00+110;
    
    SetCursorPos(i+dir[2*k],j+dir[2*k+1]);
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
       mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);

    SetCursorPos(i,j);
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
       mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
    Sleep(100);
//   }
//   i=i+48;  
//  }
//  j=j+48;
 }
 }

// SetTimer(1,5000,NULL);
}

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章