Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get Chrome URL & Process Name

Posted on 2011-03-01
12
Medium Priority
?
2,546 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

971 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