CSDN博客

img kingdog

征途洪峰

发表于2008/10/2 12:15:00  956人阅读

     玩征途的应该知道征途虹峰吧,这个是定时执行某脚本的助手。

      这个助手借助了spy++ lite源码的取控件源码,再利用postMessage对目标控件(选择框)进行处理。

关键源码如下:

 

 if (1==nIDEvent)
 {
  POINT pnt;
  
  RECT rc;
  HWND DeskHwnd = ::GetDesktopWindow();    //取得桌面句柄
  HDC DeskDC = ::GetWindowDC(DeskHwnd);     //取得桌面设备场景
  
  int oldRop2 = SetROP2(DeskDC, R2_NOTXORPEN);
  ::GetCursorPos(&pnt);                //取得鼠标坐标
  HWND UnHwnd = ::WindowFromPoint(pnt) ;    //取得鼠标指针处窗口句柄
  
  g_hWnd=UnHwnd;
  HWND grayHwnd = ::GetWindow(g_hWnd, GW_CHILD);
  RECT tempRc;
  BOOL bFind=FALSE;
  while (grayHwnd)
  {
   ::GetWindowRect(grayHwnd, &tempRc);
   if(::PtInRect(&tempRc,pnt))
   {
    bFind = TRUE;
    break;
   }
   else
    grayHwnd = ::GetWindow(grayHwnd, GW_HWNDNEXT);
   
  }//while
  if(bFind == TRUE)
  {
   bFind= FALSE;
   g_hWnd = grayHwnd;
  }
  else
   ;//Wnd=UnHwnd
  
  ::GetWindowRect(g_hWnd, &rc);      //'获得窗口矩形
  
  if( rc.left < 0 ) rc.left = 0;
  if (rc.top < 0 ) rc.top = 0;
  //If() rc.Right > Screen.Width / 15 Then rc.Right = Screen.Width / 15
  //If rc.Bottom > Screen.Height / 15 Then rc.Bottom = Screen.Height / 15
  HPEN newPen = ::CreatePen(0, 3, RGB(125,0,125));    //建立新画笔,载入DeskDC
  HGDIOBJ oldPen = ::SelectObject(DeskDC, newPen);
  ::Rectangle(DeskDC, rc.left, rc.top, rc.right, rc.bottom);  //在指示窗口周围显示闪烁矩形
  //::Beep(100,100);
  Sleep(400);    //设置闪烁时间间隔
  ::Rectangle( DeskDC, rc.left, rc.top, rc.right, rc.bottom);
  
  ::SetROP2(DeskDC, oldRop2);
  ::SelectObject( DeskDC, oldPen);
  ::DeleteObject(newPen);
  ::ReleaseDC( DeskHwnd, DeskDC);
     DeskDC = NULL;
 }

    if (2==nIDEvent)
    {
     if (CheckTime())
     {
   OnStart();
  }
    }

void CMyDlg::OnStart()
{
    KillTimer(2);
  
 CButton* btn=(CButton*)FromHandle(g_hWnd);
 if (btn)
 {
 
  ::PostMessage(g_hWnd,WM_SETFOCUS,1,0);
  ::PostMessage(g_hWnd,WM_LBUTTONDOWN,0,0);
  Sleep(300);
  ::PostMessage(g_hWnd,WM_LBUTTONUP,0,0);
  ::PostMessage(g_hWnd,BM_SETCHECK,1,0);
  
 }
     exit(0);
}

 

 

源码见:

http://p.blog.csdn.net/images/p_blog_csdn_net/kingdog/EntryImages/20081002/洪峰助手.jpg

0 0

相关博文

我的热门文章

img
取 消
img