initialization
aKiller := WindowKiller.Create(False); // 自动创建该线程,在程序启动时就执行
end.
结合上面的程序可以给出“广告杀手”的伪实现过程:
procedure WindowKiller.Execute;
var
i: integer;
str: string;
slWindow: TStrings;
Handle, hCurrentWindow: HWnd;
szText: array[0..254] of char;
begin
slWindow := TStringList.Create;
try
while not Terminated do
begin
slWindow.Clear;
Handle := FindWindow(nil, nil);
hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
while hCurrentWindow <> 0 do
begin
if GetWindowText(hCurrentWindow, @szText, 255)>0 then
begin
str := StrPas(@szText);
if str 符合广告窗体标题的特征then
slWindow.Add(IntToStr(hCurrentWindow));
// 其他可能的根据窗体属性的判断
end;
hCurrentWindow:=GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
for i:=0 to slWindow.Count-1 do
PostMessage(HWnd(StrToInt(slWindow[i])), WM_CLOSE, 0, 0);
Sleep(1000);
end; // end-while
finally
slWindow.Free;
end;
end;
新闻热点
疑难解答