Solved

Get Chrome URL & Process Name

Posted on 2011-03-01
12
2,478 Views
Last Modified: 2012-08-14
Hi, how can I get the Chrome URL and the process name from the active window?
0
Comment
Question by:eNarc
  • 6
  • 3
12 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 35014934
This is how you can do it with Internet Explorer...

http://www.festra.com/wwwboard/messages/3565.html
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35014943
This is another EE question where I have already answered the part of your question how to get Chrome url...

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26553357.html
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35014956
Again for you out of the above mentioned EE link:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26553357.html
unit Unit1;

interface

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

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

var
  Form1: TForm1;
  TheHandle:THandle;

implementation

{$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_AutocompleteEditView') then begin
   h:=FindWindowEx(TheHandle,0,wndClass,nil);

   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
   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
  EnumWindows(@FindGoogleChrome, Memo1.Handle);
end;

end.

Open in new window

0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 19

Accepted Solution

by:
Thommy earned 500 total points
ID: 35015052
This is a demo app to show how to control Goggle Chrome from Delphi...
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Edit1: TEdit;
    Button5: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(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_AutocompleteEditView') 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.Button2Click(Sender: TObject);
begin
  BringWindowToTop(TheHandle);
  PostMessage(TheHandle,WM_KEYDOWN,VK_F11,0);
  PostMessage(TheHandle,WM_KEYUP,VK_F11,0);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  BringWindowToTop(TheHandle);
  PostMessage(TheHandle,WM_KEYDOWN,VK_F5,0);
  PostMessage(TheHandle,WM_KEYUP,VK_F5,0);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  BringWindowToTop(TheHandle);

  PostMessage(TheHandle, WM_KEYDOWN, VK_CONTROL, 0);
  PostMessage(TheHandle, WM_KEYDOWN, Ord('2'), 0);
  PostMessage(TheHandle, WM_KEYUP, Ord('2'), LPARAM_KEYUP);
  PostMessage(TheHandle, WM_KEYUP, VK_CONTROL, LPARAM_KEYUP);
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  i: integer;
begin
  BringWindowToTop(TheHandle);

  //clear active url
  SendMessage(ActiveTabEditHwnd,EM_SETSEL,0,-1);
  SendMessage(ActiveTabEditHwnd,WM_CLEAR,0,0);

  //pass new url
  for i:=1 to length(Edit1.Text) do begin
    PostMessage(ActiveTabEditHwnd, WM_CHAR, ord(Edit1.Text[i]), 0);
  end;

  //Open new url
  PostMessage(ActiveTabEditHwnd, WM_KEYDOWN, VK_RETURN, 0);
  PostMessage(ActiveTabEditHwnd, WM_KEYUP, VK_RETURN, 0);
end;

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

end.

Open in new window

0
 
LVL 19

Expert Comment

by:Thommy
ID: 35015140
Google Chrome has a multi-process architecture, meaning tabs can run in separate processes from each other, and from the main browser process.

The name of the process is chrome.exe.

If you have spawned different processes you will find multiple chrome.exe in your process explorer...
ProcessExplorer.JPG
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35293721
Sorry mlmcc, I missed your administrative comment from 27/03/11 01:01 AM, where you asked for help on closing this question. I would have posted my recommendation earlier, if I had recognized it:

I do not understand why the question is to be deleted without assigning points!!!

In my opinion i have provided enough information to solve the problem...

Especially my following comment (ID:35014943 Author:ThommyDate:02/03/11 08:40 AM)
with a link to an EE question concerning the same problem, that I have answered before, will help the asker...
0
 
LVL 5

Author Comment

by:eNarc
ID: 35299567
Hi Sorry for the delay, my delphi had been messed up.

I've tested your code and it works perfectly, and I also object to this being closed and deleted because it has working code involved.

thankyou tommy. and sorry it had taken so long.
0
 
LVL 5

Author Comment

by:eNarc
ID: 35299585
I object this question being closed and deleted, what tommy provided is working code.

I'd like to accept this for the solution.

ID:35015052
Author:Thommy
Date:02/03/11 08:02 AM

thankyou
0
 
LVL 5

Author Closing Comment

by:eNarc
ID: 35299592
Perfect
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: how to send PJL commands to printer 3 109
Strange behavior when a form is closed 6 61
select query - oracle 16 100
Multiple image collision 13 80
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question