Código .PAS
CODE
unit fPrincipal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, comobj;
const
palavrasBloqueia: string = 'MSN,meebo,terra';
type
TfrmPrincipal = class(TForm)
Timer1: TTimer;
listPagSol: TListBox;
Label4: TLabel;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmPrincipal: TfrmPrincipal;
implementation
{$R *.dfm}
function BloqueiaURL(url: string): boolean;
var
ret: boolean;
x: integer;
strTemp: string;
begin
//Faz a comparação da url com as palavras q são proibidas
ret:=False;
strTemp:='';
for x:=1 to Length(palavrasBloqueia) do
begin
if ((palavrasBloqueia[x] = ',') or (x = Length(palavrasBloqueia))) then
begin
strTemp:=Trim(strTemp);
if Pos(strTemp,url) > 0 then
begin
ret:=True;
Break;
end
else
strTemp:='';
end
else
strTemp:=strTemp + palavrasBloqueia[x];
end;
BloqueiaURL:=ret;
end;
function GetUrlFromIE(Handle: THandle; List: TStringList): boolean; stdcall;
var
hWndIE, hWndIEChild : HWND;
Buffer : array[0..255] of Char;
begin
SendMessage(Handle, WM_GETTEXT, 255, integer(@Buffer[0]));
hWndIE:=FindWindow('IEFrame', Buffer);
if hWndIE > 0 then
begin
hWndIEChild:=FindWindowEx(hWndIE, 0, 'WorkerW', nil);
if hWndIEChild > 0 then
begin
hWndIEChild:=FindWindowEx(hWndIEChild, 0, 'ReBarWindow32', nil);
if hWndIEChild > 0 then
begin
hWndIEChild:=FindWindowEx(hWndIEChild, 0, 'ComboBoxEx32', nil);
if hWndIEChild > 0 then
begin
//Pega a URL e trabalha com o valor
SendMessage(hWndIEChild, WM_GETTEXT, 255, integer(@Buffer));
if List.IndexOf(Buffer) < 0 then
List.Add(Buffer);
if BloqueiaURL(LowerCase(Buffer)) then
begin
//Fecha a janela
PostMessage(hWndIE,WM_CLOSE,0,0);
//Abre nova janela
ShellExecute(hWndIE, nil, PChar('http://www.plic-plac.com'), nil, nil, SW_SHOWNORMAL);
end;
end;
end;
end;
end;
Result:=True;
end;
procedure TfrmPrincipal.Timer1Timer(Sender: TObject);
begin
//Será executado a cada 5 segundos
EnumWindows(@GetUrlFromIE, LParam(listPagSol.Items));
end;
end.
No exemplo coloquei três palavras apenas MSN,meebo,terra, caso alguma delas seja digita ele bloqueia e abre nova janela com outra página. Lembrando que funciona somente para o IE.
Para fazer o download
clique aqui !