以前别人的解答,我没测试。
function EnumWindowsProc(AHWnd: HWnd; LPARAM: lParam): boolean; stdcall;
var
WndCaption: array[0..254] of char;
WndClassName: array[0..254] of char;
rtscreen: trect;
WinXY:TRect;
xy:TPoint;
begin
GetWindowText(AHWnd, @WndCaption, 254);
GetClassName(AHWnd, @WndClassName, 254);
if (pos('CashSurfers.com',wndcaption)<>0) then //用你已知的窗口标题替换这里, 找到此窗口
begin
ahwnd:=findwindowEX(ahwnd,0,pchar('TButton'),pchar('Cool!')); // 找到窗口上的按钮
GetWindowRect(AHWnd,WinXY); // 得到按钮的坐标范围
xy:=WinXY.TopLeft; // 取得按钮左上角的坐标
xy.x:=xy.x+10;
xy.y:=xy.y+10;
SetCursorPos(xy.x,xy.y); // 将Mouse定位到按钮上
Mouse_Event(MOUSEEVENTF_LEFTDown,xy.x,xy.y,0,0); // 按下左键
Mouse_Event(MOUSEEVENTF_LEFTUP, xy.x,xy.y,0,0); // 按下右键
end;
Result := True ;
end;