antiblock
diamwall
  • Chatbox

    Did you check out our Discord? https://discord.gg/FFdvMjk9xA
    You don't have permission to chat.
    Load More
Sign in to follow this  
V¡®u§

Capturando Url Do Navegador Com Delphi

2 posts in this topic

A dúvida de muitos não está em como fazer para capturar a url do navegador mas sim em como fazer para adicionar em um 'memo' sem que fique repetindo toda hora a mesma url, afinal dependendo do objetivo do programa você não vai querer 100 mil caracteres repetido, geralmente a pessoa quer apenas verificar a url especifica.

Aqui vai a dica pra quem está precisando:

Adicione 1 Tmemo da paleta Standard

Adicione um TTimer da paleta System

Mude as propriedades do Tmemo conforme abaixo:

Align = alClient

Alignment = TaCenter

O resto deixe como esta.

Insira a seguinte variavel global logo abaixo de Form1 : TForm1:

norepeat : tstringlist;

Abaixo de {$R *.dfm} insira a função que captura a URL do navegador, em nosso exemplo vamos usar o Chrome:

Function GetActivePageUrlFromChrome(Handle: HWnd; Param: LParam): Bool; stdcall;

var

List: TStrings;

hWndChrome, hWndChromeChild: HWND;

Buffer : array[0..1000] of Char;

begin

asm

nop

end;

List := TStrings(Param);

//pega o caption da janela

SendMessage(Handle, WM_GETTEXT, Length(Buffer), integer(@Buffer[0]));

//pega o Buffer do caption

hWndChrome := FindWindow('Chrome_WidgetWin_1', Buffer);

if hWndChrome &--#60;&--#62; 0 then

begin

hWndChromeChild := FindWindowEx(hWndChrome, 0, 'Chrome_OmniboxView', nil);

if hWndChromeChild &--#60;&--#62; 0 then

begin

SendMessage(hWndChromeChild, WM_GETTEXT, Length(Buffer), integer(@Buffer));

List.Add(Buffer);

end;

end;

Result := True;

end;

6° Insira o seguinte código no evento onCreate do Form:

// limpa o memo1

memo1.Text := '';

//Abre a instancia do mecanismo de não repetição, ou melhor cria o objeto

norepeat := TStringlist.Create;

Insira o seguinte código no timer1 de modo que fique como abaixo:

procedure TForm1.Timer1Timer(Sender: TObject);

var

slChromeUrl : TstringList;

i : integer;

Existe : Boolean;

begin

try

existe := False;

slChromeUrl := TstringList.Create;

EnumWindows(@GetActivePageUrlFromChrome, LParam(slChromeUrl));

for i := 0 to norepeat.Count -1 do

begin

if (norepeat.Strings = slChromeUrl.Strings[0]) then

begin

Existe := True;

break;

end else

Existe := False;

end;

if (existe = false) then

begin

if slChromeUrl.strings[0] &--#60;&--#62; '' then

begin

norepeat.Add(slChromeUrl.Strings[0]);

Memo1.Lines.Add('-------------------------------------------');

Memo1.lines.Add(slChromeUrl.Strings[0]);

end;

end;

FreeAndNil(slChromeUrl);

except

end;

end;

Execute o nosso pequeno exemplo, abra o seu navegador Chrome e veja o resultado.

Share this post


Link to post
Share on other sites
antiblock
Elveron

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this