Solved

Get Chrome URL & Process Name

Posted on 2011-03-01
12
2,467 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 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