• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5397
  • Last Modified:

Delphi - Getting current URL from Chrome

How should I receive the current URL of Chrome, from Delphi application ?
0
oferlll
Asked:
oferlll
1 Solution
 
ThommyCommented:
Does not work on WIN7 with wndClass = 'Chrome_AutocompleteEditView' in function GetGoogleActiveTabAddress(..)

On WIN7 you have to use wndClass = 'Chrome_OmniboxView' .

Try changed code...
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  TheHandle:THandle;
  TabCount: integer;
  ActiveTab: integer;
  ActiveTabEditHwnd: hwnd;

implementation

const
  LPARAM_KEYUP = $C000;

{$R *.dfm}

function GetGoogleActiveTabAddress(wnd: THandle; Param: Integer): Bool; stdcall;
var
 wndClass: array[0..127] of char;
 len:integer;
 h:hwnd;
 S:string;
 i:integer;
begin
 //Get the object class name.
 GetClassName(wnd, wndClass, SizeOf(wndClass));

 if (wndClass = 'Chrome_OmniboxView') or             //for WIN7
    (wndClass = 'Chrome_AutocompleteEditView')       //for XP 
   then begin
   h:=FindWindowEx(TheHandle,0,wndClass,nil);

   ActiveTabEditHwnd:=h;

   len:=SendMessage(h, WM_GETTEXTLENGTH, 0, 0);

   SetLength(S, len);

   SendMessage(h, WM_GETTEXT, len+1, lparam(@S[1]));

   for i:=1 to length(S) do begin
     SendMessage(Param, WM_CHAR, ord(S[i]), 0); //Paste from the ClipBoard to the Memo1.
   end;
   SendMessage(Param, WM_CHAR, 13, 0); //Send ENTER to the Memo1.



 end;
 Result := True;                               //Continue searching.
end;

function FindGoogleChrome(wnd: THandle; Param: Integer): Bool; stdcall;
var
 wndClass: array[0..127] of char;
begin
 //Get the object class name.
 GetClassName(wnd, wndClass, SizeOf(wndClass));

 if wndClass = 'Chrome_WidgetWin_0' then begin
   inc(TabCount);
   TheHandle:=wnd;
   EnumChildWindows(wnd, @GetGoogleActiveTabAddress, Param); //Enum the child objects.
 end;
 Result := True; //Continue searching other IExplorer windows.
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  TabCount:=0;
  EnumWindows(@FindGoogleChrome, Memo1.Handle);
  ActiveTab:=0;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Lines.clear;
  Button1Click(self);
end;

end.

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now