七液 发表于 2012-12-18 00:39:08

[原创]Delphi模拟点击按钮

小七网络原创代码.作者:七液
{
函数功能: 模式鼠标点击窗口

函数说明:
    这个函数属于同步工作,最好创建新线程来执行
}
procedure MouseClick();
var
hWindow: HWND;
stPos: TPoint;
stRect: TRect;
begin
while (True) do
begin
    hWindow := FindWindow(nil, '需要点击的窗口');
    if (hWindow <> 0) then
    begin
      GetCursorPos(stPos);

      //让窗口出来[鼠标点击]需要窗体在最前面
      ShowWindow(hWindow, SW_SHOW);
      //控制窗口位置需要在最前面
      SetWindowPos(hWindow, HWND_TOPMOST, 0, 0, 490, 140, SWP_NOSIZE);

      //获取窗口尺寸
      GetWindowRect(hWindow, stRect);
      //鼠标光标移动到按钮下 225 和430 用spy++获取坐标
      SetCursorPos(225 + stRect.Left, 430 + stRect.Top);

      //模拟点击
      mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
      mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
      mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

      //还原位置
      SetCursorPos(stPos.X, stPos.Y);
      Sleep(1000);
    end;
end;
end;

lengxue 发表于 2012-12-18 11:58:04

还可以
页: [1]
查看完整版本: [原创]Delphi模拟点击按钮