Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get Chrome URL & Process Name

Posted on 2011-03-01
12
Medium Priority
?
2,525 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 19

Accepted Solution

by:
Thommy earned 2000 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

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.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

721 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