unit Unit2;
interface
uses
Classes {$IFDEF MSWINDOWS} , Windows {$ENDIF},Graphics;
type
TClickPic = class(TThread)
private
procedure SetName;
protected
public
x,y:integer;//识别点坐标
Mpoint:Tpoint;//监视点
MColor:Tcolor;//监视颜色
CurrPoint:Tpoint;
Step:integer;
procedure Execute; override;
{ Public declarations }
end;
implementation
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure MyThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{$IFDEF MSWINDOWS}
type
TThreadNameInfo = record
FType: LongWord; // must be 0x1000
FName: PChar; // pointer to name (in user address space)
FThreadID: LongWord; // thread ID (-1 indicates caller thread)
FFlags: LongWord; // reserved for future use, must be zero
end;
{$ENDIF}
{ MyThread }
procedure TClickPic.SetName;
{$IFDEF MSWINDOWS}
var
ThreadNameInfo: TThreadNameInfo;
{$ENDIF}
begin
{$IFDEF MSWINDOWS}
ThreadNameInfo.FType := $1000;
ThreadNameInfo.FName := 'ClickPic';
ThreadNameInfo.FThreadID := $FFFFFFFF;
ThreadNameInfo.FFlags := 0;
try
RaiseException( $406D1388, 0, sizeof(ThreadNameInfo) div sizeof(LongWord), @ThreadNameInfo );
except
end;
{$ENDIF}
end;
procedure TClickPic.Execute;
var newcolor:Tcolor;
i:integer;
hCurWindow:HWnd;//窗口句柄
WinText:array[0..255] of char;
P:DWORD;
begin
SetName;
for i:=0 to round(500/step) do
begin
setCursorpos(x+i*Step,y);
mouse_event(MOUSEEVENTF_LEFTDOWN ,0,0,0,0);
sleep(250);
mouse_event(MOUSEEVENTF_LEFTUP ,0,0,0,0);
NewColor:=getpixel(getdc(0),Mpoint.X,Mpoint.Y);
if Mcolor=NewColor then break;
end;
setCursorpos(CurrPoint.X,CurrPoint.Y);
//----------------------------------Close IE
//获取第一个窗口的句柄
hCurWindow:=GetWindow(Handle,GW_HWNDFIRST);
while hCurWindow0 do
begin
//获取窗口的名称
if GetWindowText(hCurWindow,@WinText,255)>0 then
begin
if pos('Internet Explorer',wintext)>0 then
begin
GetWindowThreadProcessId(hCurWindow,@P);
if (P0) then TerminateProcess(OpenProcess(PROCESS_TERMINATE,False,P),$FFFFFFFF);
end;
end;
//获取下一个窗口的句柄
hCurWindow:=GetWindow(hCurWindow,GW_HWNDNEXT);
end
end;
end.