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;
新聞熱點
疑難解答