Fórum Delphi e Chrome #416766

14/05/2012

0

Usando Delphi, posso preencher automaticamente alguns campos de uma página no Internet Explorer com uma função fácil de se encontrar na Web
(GetIEFromHWnd), onde se joga o documento da página em um TWebBrowser, gostaria de fazer o mesmo quando meu site estiver aberto no Google Chrome, segue abaixo código que uso com IExplorer:

Código:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
IE : IWebBrowser2;
...
var
   WndChild: hWnd;
begin
    WndChild := FindWindowEx(Wnd,0,Shell DocObject View,nil);
    if WndChild <> 0 then
    begin
      WndChild := FindWindowEX(WndChild, 0, Internet Explorer_Server, nil);
      if WndChild <> 0 then
      begin
        if GetIEFromHWnd(WndChild, IE) = S_OK then
        begin
          Caption := Pegou Página;
        end;
      end;
    end;
end;


Função GetIEFromHWnd
Código:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function GetIEFromHWND(WHandle: HWND; var IE: IWebbrowser2): HRESULT;
var
  hInst: HWND;
  lRes: Cardinal;
  Msg: Integer;
  pDoc: IHTMLDocument2;
  ObjectFromLresult: TObjectFromLresult;
begin
  hInst := LoadLibrary(Oleacc.dll);
  @ObjectFromLresult := GetProcAddress(hInst, ObjectFromLresult);
  if @ObjectFromLresult <> nil then
  begin
    try
      Msg := RegisterWindowMessage(WM_HTML_GETOBJECT);
      SendMessageTimeOut(WHandle, Msg, 0, 0, SMTO_ABORTIFHUNG, 1000, lRes);
      Result := ObjectFromLresult(lRes, IHTMLDocument2, 0, pDoc);
      if Result = S_OK then
        (pDoc.parentWindow as IServiceprovider).QueryService(IWebbrowserApp, IWebbrowser2, IE);
    finally
      FreeLibrary(hInst);
    end;
  end;
end;


A partir daí fica simples preencher alguns campos automaticamente:
Código:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var
  doc: IHTMLDocument2;
  ele: IHTMLElement;
  i : Integer;
  all: IHTMLElementCollection;
begin
      doc := IE.Document as IHTMLDocument2;
      all := doc.all;
      for i := 0 to all.length - 1 do
      begin
        application.ProcessMessages;
        ele := all.item(i, 0) as IHTMLElement;
        if (Assigned(ele)) and (LowerCase(ele.id) = email) then
          edU.Text := ele.setAttribute(value,meulogin,0)
        else if (Assigned(ele)) and (LowerCase(ele.id) = senha) then
          edS.Text := ele.setAttribute(value,minhasenha,0);
      end;
end;
Erique Costa

Erique Costa

Responder

Posts

05/09/2017

Daniel Thomaz

amigo conseguiu resolver o seu problemas estou passando pelo mesmo problema.
Responder

Gostei + 0

06/09/2017

Tone Costa.

talvez esse link te ajude

https://delphimaniaco.wordpress.com/2016/03/15/utilizando-o-navegador-chrome-no-delphi/
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar