Search the Community
Showing results for tags 'Capturando url do navegador com Delphi'.
Found 1 result
-
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: 1° Adicione 1 Tmemo da paleta Standard 2° Adicione um TTimer da paleta System 3° Mude as propriedades do Tmemo conforme abaixo: Align = alClient Alignment = TaCenter O resto deixe como esta. 4° Insira a seguinte variavel global logo abaixo de Form1 : TForm1: norepeat : tstringlist; 5° 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; 7° 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; 8° Execute o nosso pequeno exemplo, abra o seu navegador Chrome e veja o resultado.